How do I define a struct using more than 1 line?
type Page struct {
Title string
ContentPath string
}
//this is giving me a syntax error
template := Page{
Title: "My Title",
ContentPath: "/some/file/path"
}
How do I define a struct using more than 1 line?
type Page struct {
Title string
ContentPath string
}
//this is giving me a syntax error
template := Page{
Title: "My Title",
ContentPath: "/some/file/path"
}
You need to end all lines with a comma.
This is because of how semicolons are auto-inserted.
http://golang.org/ref/spec#Semicolons
Your current code ends up like
template := Page{
Title: "My Title",
ContentPath: "/some/file/path";
};
Adding the comma gets rid of the incorrect semicolon, but also makes it easier to add new items in the future without having to remember to add the comma above.
You're just missing a comma after the second field:
template := Page{
Title: "My Title",
ContentPath: "/some/file/path",
}