restful-hello-world.go 430 B

12345678910111213141516171819202122
  1. package main
  2. import (
  3. "github.com/emicklei/go-restful"
  4. "io"
  5. "net/http"
  6. )
  7. // This example shows the minimal code needed to get a restful.WebService working.
  8. //
  9. // GET http://localhost:8080/hello
  10. func main() {
  11. ws := new(restful.WebService)
  12. ws.Route(ws.GET("/hello").To(hello))
  13. restful.Add(ws)
  14. http.ListenAndServe(":8080", nil)
  15. }
  16. func hello(req *restful.Request, resp *restful.Response) {
  17. io.WriteString(resp, "world")
  18. }