I've started a small personal API as a learning exercise with Go and while trying to test it I found that the endpoint GET /find/{id}
isn't triggered when doing such call in Postman.
Mux Router:
router.HandleFunc("/find/{id}", controller.Find).Methods("GET")
Controller method:
func Find(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
...
}
And the former call to the API:
localhost:8080/find/[cb&%AD%87"%8CV
Maybe it's something really simple that I can't really see?
I'm using Gorilla mux,
The implementation is similar, and you can read more about it in here
package HTTPServer
import (
"net/http"
"github.com/gorilla/mux"
)
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route
var routes = Routes{
{"GetFirstForm", "GET", "/firstForm/{id}", GetFirstForm}{
//GetFirstForm getting first form by ECO id
func GetFirstForm(w http.ResponseWriter, r *http.Request) {
var vars = mux.Vars(r)
ecoID := vars["id"]
///your logic
}