Skip to content

Commit

Permalink
two route example
Browse files Browse the repository at this point in the history
  • Loading branch information
emicklei committed Apr 1, 2023
1 parent c3cfdc0 commit 9a53066
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions examples/trimslash/restful-hello-world.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ import (

// This example shows the minimal code needed to get a restful.WebService working.
//
// GET http://localhost:8080/hello
// GET http://localhost:8080/hello/
// curl http://localhost:8080/hello -> world
// curl http://localhost:8080/hello/ -> to you

func main() {
restful.MergePathStrategy = restful.TrimSlashStrategy
ws := new(restful.WebService)
ws.Route(ws.GET("/hello").To(hello))
ws.Route(ws.GET("/hello/").To(hello))
ws.Route(ws.GET("/hello").To(hello1))
ws.Route(ws.GET("/hello/").To(hello2))
restful.Add(ws)
log.Fatal(http.ListenAndServe(":8080", nil))
}

func hello(req *restful.Request, resp *restful.Response) {
func hello1(req *restful.Request, resp *restful.Response) {
io.WriteString(resp, "world")
}

func hello2(req *restful.Request, resp *restful.Response) {
io.WriteString(resp, "to you")
}

0 comments on commit 9a53066

Please sign in to comment.