package main import ( "github.com/emicklei/go-restful" ) func main() { ws := new(restful.WebService) ws.Route(ws.GET("/hello").To(helloHandler)) ... container := restful.NewContainer() container.Add(ws) ... } func helloHandler(req *restful.Request, resp *restful.Response) { resp.WriteEntity("Hello, world!") }
package main import ( "github.com/emicklei/go-restful" ) func main() { ws := new(restful.WebService) ws.Route(ws.GET("/users/{user-id}").To(userHandler)) ... container := restful.NewContainer() container.Add(ws) ... } func userHandler(req *restful.Request, resp *restful.Response) { userID := req.PathParameter("user-id") // get the value of the `user-id` path parameter ... }This code defines a GET route `/users/{user-id}` that expects a URL parameter `user-id` and maps it to the `userHandler` function that extracts the value of the parameter using `PathParameter()` method. Package library: go github.com.emicklei.go-restful