restful-path-tail.go 692 B

1234567891011121314151617181920212223242526
  1. package main
  2. import (
  3. "io"
  4. "net/http"
  5. . "github.com/emicklei/go-restful"
  6. )
  7. // This example shows how to a Route that matches the "tail" of a path.
  8. // Requires the use of a CurlyRouter and the star "*" path parameter pattern.
  9. //
  10. // GET http://localhost:8080/basepath/some/other/location/test.xml
  11. func main() {
  12. DefaultContainer.Router(CurlyRouter{})
  13. ws := new(WebService)
  14. ws.Route(ws.GET("/basepath/{resource:*}").To(staticFromPathParam))
  15. Add(ws)
  16. println("[go-restful] serve path tails from http://localhost:8080/basepath")
  17. http.ListenAndServe(":8080", nil)
  18. }
  19. func staticFromPathParam(req *Request, resp *Response) {
  20. io.WriteString(resp, "Tail="+req.PathParameter("resource"))
  21. }