那么,有什么具体的原因不能让Proxy自己的结构?
无论如何,您有两个选择:
正确的方法,只需将代理移动到自己的结构体,例如:
type Configuration struct {
Val string
Proxy
}
type Proxy struct {
Address string
Port string
}
func main() {
c := &Configuration{
Val: "test",
Proxy: Proxy{
Address: "addr",
Port: "port",
},
}
fmt.Println(c)
}
不太正确和丑陋的方式,但仍然工作:
c := &Configuration{
Val: "test",
Proxy: struct {
Address string
Port string
}{
Address: "addr",
Port: "80",
},
}