- 新增 mapSlice1 函数支持通过反射映射切片元素 - 实现 makeMapperFunc 函数动态创建映射函数- 添加 inspectMethods 和 executeFirstVoidMethod 等方法用于检查和执行结构体方法 -重构 main29 和 main30 示例以展示新增的反射能力 - 修改 Purchase 结构体字段顺序以优化内存布局 -重命名 Purchase 的 calcTotal 方法为 GetTotal 提高一致性 - 将 Customer.GetName 方法移至正确位置避免重复定义
34 lines
436 B
Go
34 lines
436 B
Go
package main
|
|
|
|
type Product struct {
|
|
Name, Category string
|
|
Price float64
|
|
}
|
|
|
|
type Customer struct {
|
|
Name, City string
|
|
}
|
|
|
|
type Payment struct {
|
|
Currency string
|
|
Amount float64
|
|
}
|
|
|
|
type ProductPayment struct {
|
|
Payment `alias:"pay"`
|
|
}
|
|
|
|
type Purchase struct {
|
|
Product
|
|
Customer
|
|
ProductPayment
|
|
Total float64
|
|
taxRate float64
|
|
}
|
|
|
|
type Person struct {
|
|
Name string `alias:"id"`
|
|
City string `alias:""`
|
|
Country string
|
|
}
|