Cloud Stack Ninja

This is my marvelous code:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/person/", func (r http.ResponseWriter, req *http.Request) {
        fmt.Println(req.Method)
    })

    _ = http.ListenAndServe(":8090", nil)
}

I'm trying to get a Post out of it on the req.Method variable making a request to http://localhost:8090/person, but my output is always GET.

I know that the Path of the request is a bit different of the paternParam in the handleFunc, but this shoud work

(https://pkg.go.dev/net/http#ServeMux)

If a subtree has been registered and a request is received naming the subtree root without its trailing slash, ServeMux redirects that request to the subtree root (adding the trailing slash). This behavior can be overridden with a separate registration for the path without the trailing slash. For example, registering "/images/" causes ServeMux to redirect a request for "/images" to "/images/", unless "/images" has been registered separately.

am I doing something wrong?



Read more here: https://stackoverflow.com/questions/64398809/making-a-post-on-handlefunc-but-only-geting-get-net-http-module

Content Attribution

This content was originally published by Fábio Fialho at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: