Tuesday, May 7, 2024
HomeGolangGo run server.go why am i getting this error when beginning -...

Go run server.go why am i getting this error when beginning – Getting Assist


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

package deal major

import (
	"log"
	"web/http"

	"github.com/gorilla/mux"
)

func major() {

	log.Println("Server will begin at http://localhost:8000/")

	route := mux.NewRouter()

	AddApproutes(route)

	log.Deadly(http.ListenAndServe(":8000", route))
}

routes.go

package deal major

import (
	"log"

	"github.com/gorilla/mux"
)


func AddApproutes(route *mux.Router) {

	log.Println("Loadeding Routes...")

	route.HandleFunc("https://discussion board.golangbridge.org/", RenderHome)

	route.HandleFunc("/sendEmail", SendEmailHandler).Strategies("POST")

	log.Println("Routes are Loaded.")
}

As a result of there is no such thing as a AddApproutes outlined in server.go. The major package deal is particular, it doesn’t robotically be a part of all information in the identical folder. It’s essential to create one other package deal, transfer that perform there, import it from server.go.

As they’re in the identical package deal you solely must specify the routes.go file in your run or construct command linel, say go run major.go routes.go

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments