I am trying to build a simple router in Go.
As I understand it url.Parse returns both an error and the parsed url, despite including both these in the assignment I am still getting the error in the title of this question
func (router *Router) Get(urlString string, callback func(Res, Req)) {
parsedUrl, err := *url.Parse(urlString)
router.Methods["GET"][parsedUrl] = callback
}
Try removing the *
in *url.Parse(urlString)
.
func (router *Router) Get(urlString string, callback func(Res, Req)) {
parsedUrl, err := url.Parse(urlString)
router.Methods["GET"][parsedUrl] = callback
}
Also, as the url.Parse()
function returns an error, your Get()
function should do something with it (preferably return it, but otherwise log it, panic etc.)