Answer the question
In order to leave comments, you need to log in
How to add data to an array of go structures?
type struct1 struct {
NameList []struct2
}
type struct2 struct {
ID int
FuncList []struct3
}
type struct3 struct {
Date []string
Power int
Intelect int
}
pers = struct1{}
pers.NameList[0].ID = 1
pers.NameList[1].ID = 2
len(pers.NameList[0]) = 0
.\main.go:107:9: cannot use form["name_lucru"] (type []string) as type profList2 in append
.\main.go:107:9: append(prForm.Proflist, form["name_lucru"]) evaluated but not used
type profList struct {
Proflist []profList2 `json:"Proflist"`
}
type profList2 struct {
NameProf string `json:"NameProf"`
OrarProf int16 `json:"OrarProf"`
PersList []profList3 `json:"PersList"`
}
type profList3 struct {
NameLucr string `json:"NameLucr"`
PrenumeLucr string `json:"PrenumeLucr"`
Begconc1 string `json:"Begconc1"`
Endconc1 string `json:"Endconc1"`
Begconc2 string `json:"Begconc2"`
Endconc2 string `json:"Endconc2"`
}
Answer the question
In order to leave comments, you need to log in
Is the idea clear?
https://play.golang.org/p/Qg9pe1K7X9I
package main
import "fmt"
type struct1 struct {
NameList []struct2
}
type struct2 struct {
ID int
FuncList []struct3
}
type struct3 struct {
Date []string
Power int
Intelect int
}
func main(){
Struct3 := struct3{}
Struct3.Date = append(Struct3.Date, "date1", "date2")
Struct3.Date = append(Struct3.Date, "date3")
Struct2 := struct2{}
Struct2.FuncList = append(Struct2.FuncList, Struct3)
Struct1 := struct1{}
Struct1.NameList = append(Struct1.NameList, Struct2)
fmt.Printf("%+v", Struct1)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question