go结构体组合
go没有继承。
类似于Java继承,SecurityGroup类继承了SecurityGroupRule列表类。
type SecurityGroup struct {
Id string
Name string
Rules []SecurityGroupRule
}
type SecurityGroupRule struct {
Id string
SrcPort uint16
DstPort uint16
}
go提倡组合,通过组合构建新的结构体,灵活度更高。
type SecurityGroup struct {
Id string
Name string
}
type SecurityGroupRule struct {
Id string
SrcPort uint16
DstPort uint16
}
type SecurityGroupRules struct {
Rules []SecurityGroupRule
}
type SecurityGroupAndRules struct {
SecurityGroup
SecurityGroupRules
}