i can not figure out this problem ,anyone can help?
panic: runtime error: index out of range
goroutine 1 [running]: 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
}