can someone tell me whats wrong with my code here.
getting a undefined Routers in Routers.RegHandler
package main
import (
_ "tracking_backend/routes"
"github.com/gorilla/mux"
)
func init() {
r := mux.NewRouter()
r.Handle("/", &Routers.RegHandler{})
}
routes/Routers.go
package routes
import (
"fmt"
"net/http"
)
type RegHandler struct {
Name string
}
func (h *RegHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hi %s!\n", "eoin")
}
**评论:**
ZetaHunter:
eoin_ahern:underscore import does not add anything to the scope, it's only useful for side-effects of imports, ie. running init().
what you want is regular import, and use
routes
as that is what your package name is, notRouters
.
cheers. that sorted me out. go has some strange quirks
