Please help how can i solve this issue, Im getting this error
cannot use Title1 (type []c) as type []string in append.
Once i append on this line
Article=append(Article,Title1)
Thanks
type a struct {
Title []b
Title1 []c
Article [][]string
}
type b struct{
DD string
FF int
}
type c struct{
CC string
EE string
}
type d struct{
DD string
}
func main() {
xx:=b{}
Title:=[]b{}
yy:=c{}
Title1:=[]c{}
Article:=[][]string{}
for i:=0; i<=2; i++{
xx.DD=strconv.Itoa(i)+"a"
xx.FF=i
Title=append(Title,xx)
Title1=nil
for ii:=0; ii<=2; ii++{
yy.CC=strconv.Itoa(ii)+"b"
yy.EE=strconv.Itoa(ii)+"c"
Title1=append(Title1,yy)
}
fmt.Println(Title1)
Article=append(Article,Title1)
}
var data = &a{
Title: Title,
Article: Article,
}
fmt.Println(data)
tmpl := template.Must(template.New("test").Parse(tmplSrc))
tmpl.Execute(os.Stdout, data)
}
Thanks in advance
You are trying to append Title1
(type []c
) to Article
(type [][]string
).
You can only append items of type []string
to Article
. So you would either need to change the type of Article
or create a new variable (like TitleStr
) which is of type []string
.