I'm trying to create a map of slices and I have the following code that works.
StringMap := map[string][]string{
"numbers": []string{"1", "2"},
"programs": []string{"red"},
}
But if I put it inside this function:
func RenderContents(responseWriter http.ResponseWriter) {
var page Model.Page = Model.Page {
TemplateFilename: "template.html",
StringMap := map[string][]string{
"numbers": []string{"1", "2"},
"programs": []string{"red"},
}
}
}
I get the following errors: syntax error: unexpected :=, expecting comma or } extra expression in var declaration syntax error: unexpected : at end of statement
I'm a newbie to Go so not sure if there's an obvious answer, but any help is appreciated.
There's a missing comma at the end of StringMap
declaration. Also, you are using :=
for StringMap
initialization. It should be :
since the initialization is for a map key:
func RenderContents(responseWriter http.ResponseWriter) {
var page Model.Page = Model.Page {
TemplateFilename: "template.html",
StringMap: map[string][]string{
"numbers": []string{"1", "2"},
"programs": []string{"red"},
},
}
}