Wednesday, March 22, 2023
HomeGolangGo run server.go why am i obtaining this mistake when beginning -...

Go run server.go why am i obtaining this mistake when beginning – Obtaining Aid


server.go:16:2: undefined: AddApproutes
server.go

 plan 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

 plan 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(" MESSAGE").

log.Println(" Courses are Packed.").
}


Since there is no AddApproutes specified in server.go The primary plan is unique, it does not immediately sign up with all data in the exact same folder. You require to develop an additional plan, step that operate there, import it from server.go

As they remain in the exact same plan you just require to define the routes.go documents in your run or construct command linel, state 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 as well as SendEmailHandler features. For instance

> > func RenderHome( w http.ResponseWriter, r * http.Request) {
>>.
> > w.WriteHeader( http.StatusOK).
>>.
> > fmt.Fprintf( w, "Hi, Globe!").
>>.
> >}
>>.
> > func SendEmailHandler( w http.ResponseWriter, r * http.Request) {
>>.
> >}

RELATED ARTICLES

Most Popular

Recent Comments