'Go rest handler views every request as GET

So basically I am trying to build this simple REST API, and I have this createCartHandler that every time I call it using postman it looks like the request method is GET. So no matter how I do the request, r.Method will be GET. Do you know what could cause this?

Also, if I do the request using something like cURL (curl -XPOST'http://localhost:8080/v1/create') it looks like it doesn't even view the request, like it is pointless.

type Service struct {
    cache *lru.Cache
}

func (s *Service) createCartHandler() http.HandlerFunc {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Println(r.Method)

        ....

    })
}


func main() {
    cache, err := lru.New(1024)
    if err != nil {
        log.Panicf("Faild to create cache: %v", err)
    }

    svc := &Service{
        cache: cache,
    }

    ...

    mux := http.NewServeMux()

    mux.Handle("/v1/create/", svc.createCartHandler())

    address := hostport


    ...

    log.Print("Listening on ", hostport)
    // When running on docker mac, can't listen only on localhost
    panic(http.ListenAndServe(address, mux))
}
go


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source