server.go:16:2: undefined: AddApproutes
server.go
bundle primary.
import (.
" log".
" net/http".
" github.com/gorilla/mux".
).
func primary() {
log.Println(" Web server will certainly begin at http://localhost:8000/").
path:= mux.NewRouter().
AddApproutes( path).
log.Fatal( http.ListenAndServe(":8000", path)).
}
routes.go
bundle primary.
import (.
" log".
" github.com/gorilla/mux".
).
func AddApproutes( path * mux.Router) {
log.Println(" Loadeding Routes ...").
route.HandleFunc(" https://forum.golangbridge.org/", RenderHome).
route.HandleFunc("/ sendEmail", SendEmailHandler). Techniques(" BLOG POST").
log.Println(" Paths are Filled.").
}
Due To The Fact That there is no AddApproutes
specified in server.go
The primary
bundle is unique, it does not instantly sign up with all data in the exact same folder. You require to develop an additional bundle, step that work there, import it from server.go
As they remain in the exact same bundle you just require to define the routes.go data in your run or develop command linel, claim go run main.go routes.go
I obtain this mistake when I include go run main.go routes.go
routes.go:14:32: undefined: RenderHome
routes.go:16:46: undefined: SendEmailHandler
You require to develop RenderHome and also SendEmailHandler features. For instance
> > func RenderHome( w http.ResponseWriter, r * http.Request) {
>>.
> > w.WriteHeader( http.StatusOK).
>>.
> > fmt.Fprintf( w, "Hey there, Globe!").
>>.
> >}
>>.
> > func SendEmailHandler( w http.ResponseWriter, r * http.Request) {
>>.
> >}