From f0557cfb6c22a896cddf2fe89b384270caf55684 Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Sat, 1 Apr 2023 11:20:37 +0200 Subject: [PATCH] examples to show differences #519 --- examples/issue519/old39/go.mod | 8 +++++ examples/issue519/old39/go.sum | 17 +++++++++++ .../issue519/old39/restful-hello-world.go | 30 +++++++++++++++++++ .../{trimslash => issue519/pathjoin}/go.mod | 0 .../{trimslash => issue519/pathjoin}/go.sum | 0 .../issue519/pathjoin/restful-hello-world.go | 30 +++++++++++++++++++ examples/issue519/trimslash/go.mod | 8 +++++ examples/issue519/trimslash/go.sum | 17 +++++++++++ .../trimslash/restful-hello-world.go | 0 9 files changed, 110 insertions(+) create mode 100644 examples/issue519/old39/go.mod create mode 100644 examples/issue519/old39/go.sum create mode 100644 examples/issue519/old39/restful-hello-world.go rename examples/{trimslash => issue519/pathjoin}/go.mod (100%) rename examples/{trimslash => issue519/pathjoin}/go.sum (100%) create mode 100644 examples/issue519/pathjoin/restful-hello-world.go create mode 100644 examples/issue519/trimslash/go.mod create mode 100644 examples/issue519/trimslash/go.sum rename examples/{ => issue519}/trimslash/restful-hello-world.go (100%) diff --git a/examples/issue519/old39/go.mod b/examples/issue519/old39/go.mod new file mode 100644 index 00000000..3386d494 --- /dev/null +++ b/examples/issue519/old39/go.mod @@ -0,0 +1,8 @@ +module github.com/emicklei/go-restful/examples/trimslash + +go 1.14 + +require ( + github.com/emicklei/go-restful/v3 v3.9.0 + github.com/json-iterator/go v1.1.12 // indirect +) diff --git a/examples/issue519/old39/go.sum b/examples/issue519/old39/go.sum new file mode 100644 index 00000000..94332298 --- /dev/null +++ b/examples/issue519/old39/go.sum @@ -0,0 +1,17 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= +github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/examples/issue519/old39/restful-hello-world.go b/examples/issue519/old39/restful-hello-world.go new file mode 100644 index 00000000..51a27571 --- /dev/null +++ b/examples/issue519/old39/restful-hello-world.go @@ -0,0 +1,30 @@ +package main + +import ( + "io" + "log" + "net/http" + + restful "github.com/emicklei/go-restful/v3" +) + +// This example shows the effect of the 3.9.0 behavior. +// +// curl http://localhost:8080/hello -> to you +// curl http://localhost:8080/hello/ -> to you + +func main() { + ws := new(restful.WebService) + ws.Route(ws.GET("/hello").To(hello1)) + ws.Route(ws.GET("/hello/").To(hello2)) + restful.Add(ws) + log.Fatal(http.ListenAndServe(":8080", nil)) +} + +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") +} diff --git a/examples/trimslash/go.mod b/examples/issue519/pathjoin/go.mod similarity index 100% rename from examples/trimslash/go.mod rename to examples/issue519/pathjoin/go.mod diff --git a/examples/trimslash/go.sum b/examples/issue519/pathjoin/go.sum similarity index 100% rename from examples/trimslash/go.sum rename to examples/issue519/pathjoin/go.sum diff --git a/examples/issue519/pathjoin/restful-hello-world.go b/examples/issue519/pathjoin/restful-hello-world.go new file mode 100644 index 00000000..67d5c398 --- /dev/null +++ b/examples/issue519/pathjoin/restful-hello-world.go @@ -0,0 +1,30 @@ +package main + +import ( + "io" + "log" + "net/http" + + restful "github.com/emicklei/go-restful/v3" +) + +// This example shows the effect of the default MergePathStrategy (restful.PathJoinStrategy). +// +// curl http://localhost:8080/hello -> world +// curl http://localhost:8080/hello/ -> 404 + +func main() { + ws := new(restful.WebService) + ws.Route(ws.GET("/hello").To(hello1)) + ws.Route(ws.GET("/hello/").To(hello2)) + restful.Add(ws) + log.Fatal(http.ListenAndServe(":8080", nil)) +} + +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") +} diff --git a/examples/issue519/trimslash/go.mod b/examples/issue519/trimslash/go.mod new file mode 100644 index 00000000..99fa77bd --- /dev/null +++ b/examples/issue519/trimslash/go.mod @@ -0,0 +1,8 @@ +module github.com/emicklei/go-restful/examples/trimslash + +go 1.14 + +require ( + github.com/emicklei/go-restful/v3 v3.10.2 + github.com/json-iterator/go v1.1.12 // indirect +) diff --git a/examples/issue519/trimslash/go.sum b/examples/issue519/trimslash/go.sum new file mode 100644 index 00000000..6ce14b49 --- /dev/null +++ b/examples/issue519/trimslash/go.sum @@ -0,0 +1,17 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful/v3 v3.10.2 h1:hIovbnmBTLjHXkqEBUz3HGpXZdM7ZrE9fJIZIqlJLqE= +github.com/emicklei/go-restful/v3 v3.10.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/examples/trimslash/restful-hello-world.go b/examples/issue519/trimslash/restful-hello-world.go similarity index 100% rename from examples/trimslash/restful-hello-world.go rename to examples/issue519/trimslash/restful-hello-world.go