Guys, I’m new in creating function in go. I’m not familiar how to can i make it a reusable code. I know how to return single variable but in terms of array or struct im not even try. here is the sample code.
type a struct {
Title []string
Article [][]string
}
func test1(res http.ResponseWriter, req *http.Request) {
var data = &a{
Title: []string{"One", "Two", "Three"},
Article: [][]string{
[]string{"a", "b", "c","b"},
[]string{},
[]string{"f", "g", "h", "i"}},
}
templating.Display(res, "test1", data)
}
func test2(res http.ResponseWriter, req *http.Request) {
var data = &a{
Title: []string{"One", "Two", "Three"},
Article: [][]string{
[]string{"a", "b", "c","b"},
[]string{},
[]string{"f", "g", "h", "i"}},
}
templating.Display(res, "test1", data)
}
I know that the data variable should taking care of the record but it is ugly to see, i think is better to put in one function then call that function , but i don’t have any idea how can i arrive like that