Gorilla Mux Optinal URL

Hi guys I need some help. How to create optional url handler in gorilla mux ?


r.HandleFunc(/login/username/{userName}/password/{password}/email/{eMail}, FikiFiki).Methods(“GET”)

Email is optional I send the all params no problem everything okay but remove the optional variable I get 404 error
How to fix this ?

Sorry for my bad English

You can create two routes for the same function, or you could consider just passing parameters as url params instead, or you can rely on prefix matching.

PS Don’t put passwords in urls, they get logged, recorded etc. and don’t use GET for actions which change state. Normally a login sequence would be:

GET login form (at say /login )
POST login form to another endpoint with the data in the body, not the url

The form of url you’ve used here is more often used as a way of addressing a specific resource, e.g.:

GET /users/{id}
GET /products/{id}

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.