I'm writing a Google App Engine Go application. In it, I want to handle some calls separately in different .go files. Should I call "init()" function separately in each of those files, or just declare it in one file and call some other functions for initialisation of each .go file?
For example, if I'd have two files, user.go:
package User
import(
"http"
"fmt"
)
func init() {
http.HandleFunc("/", hello)
}
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, user!")
}
And admin.go:
package Admin
import(
"http"
"fmt"
)
func init() {
http.HandleFunc("/admin/", hello)
}
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, admin!")
}
Is such an initialisation correct, or is it advised against something like this?