我无法弄清楚这个问题,任何人都可以帮忙吗?
恐慌:运行时错误:索引超出范围
goroutine 1 [正在运行]: main.main() /root/go/src/k8s.io/client-go/examples/in-cluster-client-configuration/test_json.go:15 +0x42
type obj struct {
Targets [2]string `json:"targets"`
Labels map[string]string `json:"labels"`
}
func main() {
// Creating simulation
var myobj = []*obj{}
n := new(obj)
myobj[0].Targets = [2]string{"10.0.0.1", "10.0.0.2"}
myobj[0].Labels = make(map[string]string)
myobj[0].Labels["job"] = "db2"
myobj = append(myobj, n)
k := new(obj)
myobj[1].Targets = [2]string{"192.168.1.12", "192.168.1.13"}
myobj[1].Labels = make(map[string]string)
myobj[1].Labels["job"] = "mysql"
myobj = append(myobj, k)
// Converting to JSON, for transmission over web
data, err := json.Marshal(myobj)
if err != nil {
fmt.Println(err)
return
}
波斯汪
梵蒂冈之花
相关分类