For example, I have a request:
POST /api/users/1/categories/2/posts/3
How can I access this params?
I've tried:
req.ParseMultipartForm(defaultMaxMemory)
req.Form.Get("id")
req.Form.Get("1")
req.Form.Get("_1")
But it doesn't work.
Same question about GET:
GET /api/users/1/categories/2/posts/3
How to get not named params?
req.URL.Query().Get(???)
If you are using the default http server library, you'll need to parse the Url path parts and extract them.
There are libraries like Gorilla Mux (which I personally like) that you can use to add this logic automatically. http://www.gorillatoolkit.org/pkg/mux
Using Gorilla/mux, when you register your handler, you register it like so:
r := mux.NewRouter()
r.HandleFunc("/api/users/{userId}/categories/{categoryId}/posts/{postId}",
MyHandler)
And then in your handler you can access them:
vars := mux.Vars(request)
userId := vars["userId"]
// etc...