我遵循了tf文件中的結構,你能幫我創建一個合適的structure,因為我是 Go 的新手。這是tf ipv4 = { cidrblock = "10.0.0.0/16" secondary = [ { cidrs = "20.0.0.0/16" enabled = true }, { cidrs = "30.0.0.0/16" enabled = true } ] }所以我有一個字符串對象,以及主對象中的對象列表。我可以制作一個原始類型,例如:type ipv4 struct { cidrblock string cidrs string enabled bool}type ipv6 struct { border string generate bool}type Sets struct { Name string IPv4 *ipv4 IPv6 *ipv6 Tags map[string]string Tenancy string}但我真的很想有一個復雜的結構
1 回答

拉莫斯之舞
TA貢獻1820條經驗 獲得超10個贊
你可以這樣做:
type ipv4 struct {
cidrblock string
secondary []ipv4secondary
}
type ipv4secondary struct {
cidrblock string
enabled bool
}
并像這樣使用它:
example := ipv4{
cidrblock: "10.0.0.0/16",
secondary: []ipv4secondary{
ipv4secondary{cidrblock: "20.0.0.0/16", enabled: true},
ipv4secondary{cidrblock: "30.0.0.0/16", enabled: true},
},
}
這是示例:https ://go.dev/play/p/U7o0BbAis9T
- 1 回答
- 0 關注
- 107 瀏覽
添加回答
舉報
0/150
提交
取消