From 9a5306637f5ed5e47c8e73d10b2f5d6dbc852bfe Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Sat, 1 Apr 2023 11:10:28 +0200 Subject: [PATCH] two route example --- examples/trimslash/restful-hello-world.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/trimslash/restful-hello-world.go b/examples/trimslash/restful-hello-world.go index 6f442070..9d02dda2 100644 --- a/examples/trimslash/restful-hello-world.go +++ b/examples/trimslash/restful-hello-world.go @@ -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") +}