From 601692bdb9017788c3b10d573c5b4473eba505bc Mon Sep 17 00:00:00 2001 From: Ernest Micklei Date: Fri, 23 Oct 2020 10:32:55 +0200 Subject: [PATCH] examples use v3 --- CHANGES.md | 10 +- Makefile | 5 +- README.md | 14 +-- examples/README.md | 1 + examples/basicauth/go.mod | 5 + examples/basicauth/go.sum | 4 + .../restful-basic-authentication.go | 3 +- examples/cors/go.mod | 5 + examples/cors/go.sum | 4 + examples/{ => cors}/restful-CORS-filter.go | 2 +- examples/cpuprof/go.mod | 5 + examples/cpuprof/go.sum | 4 + .../restful-cpuprofiler-service.go | 3 +- examples/encoding/go.mod | 5 + examples/encoding/go.sum | 4 + .../{ => encoding}/restful-encoding-filter.go | 3 +- examples/filters/go.mod | 5 + examples/filters/go.sum | 4 + examples/{ => filters}/restful-filters.go | 3 +- examples/form/go.mod | 8 ++ examples/form/go.sum | 6 + examples/{ => form}/restful-form-handling.go | 5 +- examples/fulllog/go.mod | 5 + examples/fulllog/go.sum | 4 + .../restful-full-logging-filter.go | 2 +- examples/google-custom-method/go.mod | 5 + examples/google-custom-method/go.sum | 4 + .../restful-google-custom-method.go | 3 +- examples/hello/go.mod | 5 + examples/hello/go.sum | 4 + examples/{ => hello}/restful-hello-world.go | 3 +- examples/jwtauth/go.mod | 8 ++ examples/jwtauth/go.sum | 7 ++ .../restful-jwt-authentication.go | 5 +- examples/msgpack/msgpack_entity.go | 2 +- examples/multi-container/go.mod | 5 + examples/multi-container/go.sum | 4 + .../restful-multi-containers.go | 3 +- examples/ncsa/go.mod | 5 + examples/ncsa/go.sum | 4 + examples/{ => ncsa}/restful-NCSA-logging.go | 3 +- examples/nocache/go.mod | 5 + examples/nocache/go.sum | 4 + .../{ => nocache}/restful-no-cache-filter.go | 2 +- examples/openapi/go.mod | 9 ++ examples/openapi/go.sum | 63 +++++++++++ examples/{ => openapi}/restful-openapi.go | 8 +- .../{ => options}/restful-options-filter.go | 3 +- examples/{ => pathtail}/restful-path-tail.go | 3 +- .../{ => prepost}/restful-pre-post-filters.go | 3 +- .../restful-resource-functions.go | 3 +- examples/restful-curly-router.go | 107 ------------------ examples/{ => static}/restful-serve-static.go | 2 +- examples/{ => swagger}/restful-swagger.go | 0 examples/template/go.mod | 5 + examples/template/go.sum | 4 + examples/{ => template}/home.html | 0 .../{ => template}/restful-html-template.go | 2 +- .../{ => tests}/restful-curly-router_test.go | 0 examples/{ => tests}/restful-route_test.go | 0 .../{ => tests}/restful-routefunction_test.go | 0 examples/user-resource/go.mod | 9 ++ examples/user-resource/go.sum | 56 +++++++++ .../restful-user-resource.go | 8 +- 64 files changed, 332 insertions(+), 153 deletions(-) create mode 100644 examples/README.md create mode 100644 examples/basicauth/go.mod create mode 100644 examples/basicauth/go.sum rename examples/{ => basicauth}/restful-basic-authentication.go (95%) create mode 100644 examples/cors/go.mod create mode 100644 examples/cors/go.sum rename examples/{ => cors}/restful-CORS-filter.go (97%) create mode 100644 examples/cpuprof/go.mod create mode 100644 examples/cpuprof/go.sum rename examples/{ => cpuprof}/restful-cpuprofiler-service.go (97%) create mode 100644 examples/encoding/go.mod create mode 100644 examples/encoding/go.sum rename examples/{ => encoding}/restful-encoding-filter.go (97%) create mode 100644 examples/filters/go.mod create mode 100644 examples/filters/go.sum rename examples/{ => filters}/restful-filters.go (98%) create mode 100644 examples/form/go.mod create mode 100644 examples/form/go.sum rename examples/{ => form}/restful-form-handling.go (97%) create mode 100644 examples/fulllog/go.mod create mode 100644 examples/fulllog/go.sum rename examples/{ => fulllog}/restful-full-logging-filter.go (98%) create mode 100644 examples/google-custom-method/go.mod create mode 100644 examples/google-custom-method/go.sum rename examples/{ => google-custom-method}/restful-google-custom-method.go (96%) create mode 100644 examples/hello/go.mod create mode 100644 examples/hello/go.sum rename examples/{ => hello}/restful-hello-world.go (90%) create mode 100644 examples/jwtauth/go.mod create mode 100644 examples/jwtauth/go.sum rename examples/{ => jwtauth}/restful-jwt-authentication.go (96%) create mode 100644 examples/multi-container/go.mod create mode 100644 examples/multi-container/go.sum rename examples/{ => multi-container}/restful-multi-containers.go (96%) create mode 100644 examples/ncsa/go.mod create mode 100644 examples/ncsa/go.sum rename examples/{ => ncsa}/restful-NCSA-logging.go (96%) create mode 100644 examples/nocache/go.mod create mode 100644 examples/nocache/go.sum rename examples/{ => nocache}/restful-no-cache-filter.go (91%) create mode 100644 examples/openapi/go.mod create mode 100644 examples/openapi/go.sum rename examples/{ => openapi}/restful-openapi.go (95%) rename examples/{ => options}/restful-options-filter.go (96%) rename examples/{ => pathtail}/restful-path-tail.go (94%) rename examples/{ => prepost}/restful-pre-post-filters.go (98%) rename examples/{ => resource-func}/restful-resource-functions.go (97%) delete mode 100644 examples/restful-curly-router.go rename examples/{ => static}/restful-serve-static.go (96%) rename examples/{ => swagger}/restful-swagger.go (100%) create mode 100644 examples/template/go.mod create mode 100644 examples/template/go.sum rename examples/{ => template}/home.html (100%) rename examples/{ => template}/restful-html-template.go (94%) rename examples/{ => tests}/restful-curly-router_test.go (100%) rename examples/{ => tests}/restful-route_test.go (100%) rename examples/{ => tests}/restful-routefunction_test.go (100%) create mode 100644 examples/user-resource/go.mod create mode 100644 examples/user-resource/go.sum rename examples/{ => user-resource}/restful-user-resource.go (95%) diff --git a/CHANGES.md b/CHANGES.md index 11526357..98744f26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,21 +1,21 @@ -# Change history of go-restful +# Change history of go-restful (v2 only) -## [v2.14.3] - 2020-08-31 +## v2.14.3 - 2020-08-31 - Fixed duplicate compression in dispatch. #449 -## [v2.14.2] - 2020-08-31 +## v2.14.2 - 2020-08-31 - Added check on writer to prevent compression of response twice. #447 -## [v2.14.0] - 2020-08-19 +## v2.14.0 - 2020-08-19 - Enable content encoding on Handle and ServeHTTP (#446) - List available representations in 406 body (#437) - Convert to string using rune() (#443) -## [v2.13.0] - 2020-06-21 +## v2.13.0 - 2020-06-21 - 405 Method Not Allowed must have Allow header (#436) - add field allowedMethodsWithoutContentType (#424) diff --git a/Makefile b/Makefile index cfb0cc11..3a824ac3 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,4 @@ all: test test: go vet . - go test -cover -v . - -ex: - cd examples && ls *.go | xargs go build -o /tmp/ignore \ No newline at end of file + go test -cover -v . \ No newline at end of file diff --git a/README.md b/README.md index 4b4d26e7..02f93101 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ package for building REST-style Web Services using Google Go [![GoDoc](https://godoc.org/github.com/emicklei/go-restful?status.svg)](https://pkg.go.dev/github.com/emicklei/go-restful) [![codecov](https://codecov.io/gh/emicklei/go-restful/branch/master/graph/badge.svg)](https://codecov.io/gh/emicklei/go-restful) -- [Code examples](https://github.com/emicklei/go-restful/tree/master/examples) +- [Code examples using v3](https://github.com/emicklei/go-restful/tree/master/examples) REST asks developers to use HTTP methods explicitly and in a way that's consistent with the protocol definition. This basic REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations and HTTP methods. According to this mapping: @@ -21,23 +21,23 @@ REST asks developers to use HTTP methods explicitly and in a way that's consiste ### Usage -#### Without Go Modules +#### Using Go Modules -All versions up to `v2.*.*` (on the master) are not supporting Go modules. +As of version `v3.0.0` (on the v3 branch), this package supports Go modules. ``` import ( - restful "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) ``` -#### Using Go Modules +#### Without Go Modules -As of version `v3.0.0` (on the v3 branch), this package supports Go modules. +All versions up to `v2.*.*` (on the master) are not supporting Go modules. ``` import ( - restful "github.com/emicklei/go-restful/v3" + restful "github.com/emicklei/go-restful" ) ``` diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..c778badc --- /dev/null +++ b/examples/README.md @@ -0,0 +1 @@ +## examples use v3 of the package \ No newline at end of file diff --git a/examples/basicauth/go.mod b/examples/basicauth/go.mod new file mode 100644 index 00000000..df524fc6 --- /dev/null +++ b/examples/basicauth/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/basicauth + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/basicauth/go.sum b/examples/basicauth/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/basicauth/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-basic-authentication.go b/examples/basicauth/restful-basic-authentication.go similarity index 95% rename from examples/restful-basic-authentication.go rename to examples/basicauth/restful-basic-authentication.go index f4fd5ce1..0a367b98 100644 --- a/examples/restful-basic-authentication.go +++ b/examples/basicauth/restful-basic-authentication.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to create a (Route) Filter that performs Basic Authentication on the Http request. diff --git a/examples/cors/go.mod b/examples/cors/go.mod new file mode 100644 index 00000000..76ff96a8 --- /dev/null +++ b/examples/cors/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/cors + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/cors/go.sum b/examples/cors/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/cors/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-CORS-filter.go b/examples/cors/restful-CORS-filter.go similarity index 97% rename from examples/restful-CORS-filter.go rename to examples/cors/restful-CORS-filter.go index d682d43e..8a5b2f03 100644 --- a/examples/restful-CORS-filter.go +++ b/examples/cors/restful-CORS-filter.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) // Cross-origin resource sharing (CORS) is a mechanism that allows JavaScript on a web page diff --git a/examples/cpuprof/go.mod b/examples/cpuprof/go.mod new file mode 100644 index 00000000..3502ac00 --- /dev/null +++ b/examples/cpuprof/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/cpuprof + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/cpuprof/go.sum b/examples/cpuprof/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/cpuprof/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-cpuprofiler-service.go b/examples/cpuprof/restful-cpuprofiler-service.go similarity index 97% rename from examples/restful-cpuprofiler-service.go rename to examples/cpuprof/restful-cpuprofiler-service.go index 9148213c..3afee0cf 100644 --- a/examples/restful-cpuprofiler-service.go +++ b/examples/cpuprof/restful-cpuprofiler-service.go @@ -1,11 +1,12 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "os" "runtime/pprof" + + restful "github.com/emicklei/go-restful/v3" ) // ProfilingService is a WebService that can start/stop a CPU profile and write results to a file diff --git a/examples/encoding/go.mod b/examples/encoding/go.mod new file mode 100644 index 00000000..44082633 --- /dev/null +++ b/examples/encoding/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/encoding + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/encoding/go.sum b/examples/encoding/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/encoding/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-encoding-filter.go b/examples/encoding/restful-encoding-filter.go similarity index 97% rename from examples/restful-encoding-filter.go rename to examples/encoding/restful-encoding-filter.go index 177d5a99..bff607cb 100644 --- a/examples/restful-encoding-filter.go +++ b/examples/encoding/restful-encoding-filter.go @@ -1,9 +1,10 @@ package main import ( - "github.com/emicklei/go-restful" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) type User struct { diff --git a/examples/filters/go.mod b/examples/filters/go.mod new file mode 100644 index 00000000..833681d4 --- /dev/null +++ b/examples/filters/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/filters + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/filters/go.sum b/examples/filters/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/filters/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-filters.go b/examples/filters/restful-filters.go similarity index 98% rename from examples/restful-filters.go rename to examples/filters/restful-filters.go index aaadb9d2..a021979e 100644 --- a/examples/restful-filters.go +++ b/examples/filters/restful-filters.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "log" "net/http" "time" + + restful "github.com/emicklei/go-restful/v3" ) type User struct { diff --git a/examples/form/go.mod b/examples/form/go.mod new file mode 100644 index 00000000..3565477f --- /dev/null +++ b/examples/form/go.mod @@ -0,0 +1,8 @@ +module github.com/emicklei/go-restful/examples/form + +go 1.14 + +require ( + github.com/emicklei/go-restful/v3 v3.3.3 // indirect + github.com/gorilla/schema v1.2.0 // indirect +) diff --git a/examples/form/go.sum b/examples/form/go.sum new file mode 100644 index 00000000..bed74600 --- /dev/null +++ b/examples/form/go.sum @@ -0,0 +1,6 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc= +github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= diff --git a/examples/restful-form-handling.go b/examples/form/restful-form-handling.go similarity index 97% rename from examples/restful-form-handling.go rename to examples/form/restful-form-handling.go index e85608c9..59a321db 100644 --- a/examples/restful-form-handling.go +++ b/examples/form/restful-form-handling.go @@ -2,11 +2,12 @@ package main import ( "fmt" - "github.com/emicklei/go-restful" - "github.com/gorilla/schema" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" + "github.com/gorilla/schema" ) // This example shows how to handle a POST of a HTML form that uses the standard x-www-form-urlencoded content-type. diff --git a/examples/fulllog/go.mod b/examples/fulllog/go.mod new file mode 100644 index 00000000..c9484070 --- /dev/null +++ b/examples/fulllog/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/fulllog + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/fulllog/go.sum b/examples/fulllog/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/fulllog/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-full-logging-filter.go b/examples/fulllog/restful-full-logging-filter.go similarity index 98% rename from examples/restful-full-logging-filter.go rename to examples/fulllog/restful-full-logging-filter.go index 32205b87..20a78566 100644 --- a/examples/restful-full-logging-filter.go +++ b/examples/fulllog/restful-full-logging-filter.go @@ -6,7 +6,7 @@ import ( "log" "net/http" - "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) type User struct { diff --git a/examples/google-custom-method/go.mod b/examples/google-custom-method/go.mod new file mode 100644 index 00000000..7d97e785 --- /dev/null +++ b/examples/google-custom-method/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/google-custom-method + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/google-custom-method/go.sum b/examples/google-custom-method/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/google-custom-method/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-google-custom-method.go b/examples/google-custom-method/restful-google-custom-method.go similarity index 96% rename from examples/restful-google-custom-method.go rename to examples/google-custom-method/restful-google-custom-method.go index 7f2f0e7a..2013cd76 100644 --- a/examples/restful-google-custom-method.go +++ b/examples/google-custom-method/restful-google-custom-method.go @@ -1,10 +1,11 @@ package main import ( - . "github.com/emicklei/go-restful" "io" "log" "net/http" + + . "github.com/emicklei/go-restful/v3" ) // This example shows how to create a Route with google custom method diff --git a/examples/hello/go.mod b/examples/hello/go.mod new file mode 100644 index 00000000..0b92aaa5 --- /dev/null +++ b/examples/hello/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/hello + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/hello/go.sum b/examples/hello/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/hello/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-hello-world.go b/examples/hello/restful-hello-world.go similarity index 90% rename from examples/restful-hello-world.go rename to examples/hello/restful-hello-world.go index bf987b80..d2854af5 100644 --- a/examples/restful-hello-world.go +++ b/examples/hello/restful-hello-world.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows the minimal code needed to get a restful.WebService working. diff --git a/examples/jwtauth/go.mod b/examples/jwtauth/go.mod new file mode 100644 index 00000000..c9cb7edb --- /dev/null +++ b/examples/jwtauth/go.mod @@ -0,0 +1,8 @@ +module github.com/emicklei/go-restful/examples/jwtauth + +go 1.14 + +require ( + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/emicklei/go-restful/v3 v3.3.3 // indirect +) diff --git a/examples/jwtauth/go.sum b/examples/jwtauth/go.sum new file mode 100644 index 00000000..55578a8a --- /dev/null +++ b/examples/jwtauth/go.sum @@ -0,0 +1,7 @@ +github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-jwt-authentication.go b/examples/jwtauth/restful-jwt-authentication.go similarity index 96% rename from examples/restful-jwt-authentication.go rename to examples/jwtauth/restful-jwt-authentication.go index 569036a0..c5b2d6f1 100644 --- a/examples/restful-jwt-authentication.go +++ b/examples/jwtauth/restful-jwt-authentication.go @@ -1,12 +1,13 @@ package main import ( - "github.com/dgrijalva/jwt-go" - "github.com/emicklei/go-restful" "io" "log" "net/http" "strings" + + "github.com/dgrijalva/jwt-go" + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to create a (Route) Filter that performs a JWT HS512 authentication. diff --git a/examples/msgpack/msgpack_entity.go b/examples/msgpack/msgpack_entity.go index 330e4589..0763b631 100644 --- a/examples/msgpack/msgpack_entity.go +++ b/examples/msgpack/msgpack_entity.go @@ -1,7 +1,7 @@ package restPack import ( - restful "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" "gopkg.in/vmihailenco/msgpack.v2" ) diff --git a/examples/multi-container/go.mod b/examples/multi-container/go.mod new file mode 100644 index 00000000..92bf2876 --- /dev/null +++ b/examples/multi-container/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/multi-container + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/multi-container/go.sum b/examples/multi-container/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/multi-container/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-multi-containers.go b/examples/multi-container/restful-multi-containers.go similarity index 96% rename from examples/restful-multi-containers.go rename to examples/multi-container/restful-multi-containers.go index 3056d3ea..55e13181 100644 --- a/examples/restful-multi-containers.go +++ b/examples/multi-container/restful-multi-containers.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to have a program with 2 WebServices containers diff --git a/examples/ncsa/go.mod b/examples/ncsa/go.mod new file mode 100644 index 00000000..6446a74b --- /dev/null +++ b/examples/ncsa/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/ncsa + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/ncsa/go.sum b/examples/ncsa/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/ncsa/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-NCSA-logging.go b/examples/ncsa/restful-NCSA-logging.go similarity index 96% rename from examples/restful-NCSA-logging.go rename to examples/ncsa/restful-NCSA-logging.go index 7066b96d..9f649014 100644 --- a/examples/restful-NCSA-logging.go +++ b/examples/ncsa/restful-NCSA-logging.go @@ -1,13 +1,14 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" "os" "strings" "time" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to create a filter that produces log lines diff --git a/examples/nocache/go.mod b/examples/nocache/go.mod new file mode 100644 index 00000000..a14d74cb --- /dev/null +++ b/examples/nocache/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/nocache + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/nocache/go.sum b/examples/nocache/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/nocache/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/restful-no-cache-filter.go b/examples/nocache/restful-no-cache-filter.go similarity index 91% rename from examples/restful-no-cache-filter.go rename to examples/nocache/restful-no-cache-filter.go index 8e4540f4..a9b24060 100644 --- a/examples/restful-no-cache-filter.go +++ b/examples/nocache/restful-no-cache-filter.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to use a WebService filter that passed the Http headers to disable browser cacheing. diff --git a/examples/openapi/go.mod b/examples/openapi/go.mod new file mode 100644 index 00000000..83fad92b --- /dev/null +++ b/examples/openapi/go.mod @@ -0,0 +1,9 @@ +module github.com/emicklei/go-restful/examples/openapi + +go 1.14 + +require ( + github.com/emicklei/go-restful-openapi/v2 v2.2.1 + github.com/emicklei/go-restful/v3 v3.3.1 + github.com/go-openapi/spec v0.19.10 +) diff --git a/examples/openapi/go.sum b/examples/openapi/go.sum new file mode 100644 index 00000000..5f0caf56 --- /dev/null +++ b/examples/openapi/go.sum @@ -0,0 +1,63 @@ +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +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-openapi/v2 v2.2.1 h1:9xG+IjR5kUNBNJzksOmV92DzgrBJLKCLD7uY9i5XtYI= +github.com/emicklei/go-restful-openapi/v2 v2.2.1/go.mod h1:bs67E3SEVgSmB3qDuRLqpS0NcpheqtsCCMhW2/jml1E= +github.com/emicklei/go-restful/v3 v3.0.0-rc2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.3.1 h1:engBLuFVe3n4ck963X94ZFfauROk9nthZOKilyHLgpM= +github.com/emicklei/go-restful/v3 v3.3.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= +github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= +github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= +github.com/go-openapi/jsonreference v0.19.4 h1:3Vw+rh13uq2JFNxgnMTGE1rnoieU9FmyE1gvnyylsYg= +github.com/go-openapi/jsonreference v0.19.4/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= +github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= +github.com/go-openapi/spec v0.19.10 h1:pcNevfYytLaOQuTju0wm6OqcqU/E/pRwuSGigrLTI28= +github.com/go-openapi/spec v0.19.10/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= +github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.6 h1:JSUbVWlaTLMhXeOMyArSUNCdroxZu2j1TcrsOV8Mj7Q= +github.com/go-openapi/swag v0.19.6/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +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 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +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= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/examples/restful-openapi.go b/examples/openapi/restful-openapi.go similarity index 95% rename from examples/restful-openapi.go rename to examples/openapi/restful-openapi.go index f22211ec..0f0825ef 100644 --- a/examples/restful-openapi.go +++ b/examples/openapi/restful-openapi.go @@ -6,8 +6,8 @@ import ( "log" "net/http" - "github.com/emicklei/go-restful" - restfulspec "github.com/emicklei/go-restful-openapi" + restfulspec "github.com/emicklei/go-restful-openapi/v2" + restful "github.com/emicklei/go-restful/v3" "github.com/go-openapi/spec" ) @@ -125,8 +125,8 @@ func main() { restful.DefaultContainer.Add(u.WebService()) config := restfulspec.Config{ - WebServices: restful.RegisteredWebServices(), // you control what services are visible - APIPath: "/apidocs.json", + WebServices: restful.RegisteredWebServices(), // you control what services are visible + APIPath: "/apidocs.json", PostBuildSwaggerObjectHandler: enrichSwaggerObject} restful.DefaultContainer.Add(restfulspec.NewOpenAPIService(config)) diff --git a/examples/restful-options-filter.go b/examples/options/restful-options-filter.go similarity index 96% rename from examples/restful-options-filter.go rename to examples/options/restful-options-filter.go index 79ccce55..d1d3eaf5 100644 --- a/examples/restful-options-filter.go +++ b/examples/options/restful-options-filter.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to use the OPTIONSFilter on a Container diff --git a/examples/restful-path-tail.go b/examples/pathtail/restful-path-tail.go similarity index 94% rename from examples/restful-path-tail.go rename to examples/pathtail/restful-path-tail.go index f30d6716..ef253f0a 100644 --- a/examples/restful-path-tail.go +++ b/examples/pathtail/restful-path-tail.go @@ -1,10 +1,11 @@ package main import ( - . "github.com/emicklei/go-restful" "io" "log" "net/http" + + . "github.com/emicklei/go-restful/v3" ) // This example shows how to create a Route matching the "tail" of a path. diff --git a/examples/restful-pre-post-filters.go b/examples/prepost/restful-pre-post-filters.go similarity index 98% rename from examples/restful-pre-post-filters.go rename to examples/prepost/restful-pre-post-filters.go index 0b55f149..9595e987 100644 --- a/examples/restful-pre-post-filters.go +++ b/examples/prepost/restful-pre-post-filters.go @@ -1,10 +1,11 @@ package main import ( - "github.com/emicklei/go-restful" "io" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how the different types of filters are called in the request-response flow. diff --git a/examples/restful-resource-functions.go b/examples/resource-func/restful-resource-functions.go similarity index 97% rename from examples/restful-resource-functions.go rename to examples/resource-func/restful-resource-functions.go index 09e6e566..58162386 100644 --- a/examples/restful-resource-functions.go +++ b/examples/resource-func/restful-resource-functions.go @@ -1,9 +1,10 @@ package main import ( - "github.com/emicklei/go-restful" "log" "net/http" + + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to use methods as RouteFunctions for WebServices. diff --git a/examples/restful-curly-router.go b/examples/restful-curly-router.go deleted file mode 100644 index ce99ffa3..00000000 --- a/examples/restful-curly-router.go +++ /dev/null @@ -1,107 +0,0 @@ -package main - -import ( - "log" - "net/http" - - "github.com/emicklei/go-restful" -) - -// This example has the same service definition as restful-user-resource -// but uses a different router (CurlyRouter) that does not use regular expressions -// -// POST http://localhost:8080/users -// 1Melissa Raspberry -// -// GET http://localhost:8080/users/1 -// -// PUT http://localhost:8080/users/1 -// 1Melissa -// -// DELETE http://localhost:8080/users/1 -// - -type User struct { - Id, Name string -} - -type UserResource struct { - // normally one would use DAO (data access object) - users map[string]User -} - -func (u UserResource) Register(container *restful.Container) { - ws := new(restful.WebService) - ws. - Path("/users"). - Consumes(restful.MIME_XML, restful.MIME_JSON). - Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this per route as well - - ws.Route(ws.GET("/{user-id}").To(u.findUser)) - ws.Route(ws.POST("").To(u.updateUser)) - ws.Route(ws.PUT("/{user-id}").To(u.createUser)) - ws.Route(ws.DELETE("/{user-id}").To(u.removeUser)) - - container.Add(ws) -} - -// GET http://localhost:8080/users/1 -// -func (u UserResource) findUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - usr := u.users[id] - if len(usr.Id) == 0 { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusNotFound, "User could not be found.") - } else { - response.WriteEntity(usr) - } -} - -// PUT http://localhost:8080/users/1 -// 1Melissa -// -func (u *UserResource) updateUser(request *restful.Request, response *restful.Response) { - usr := new(User) - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.Id] = *usr - response.WriteEntity(usr) - } else { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusInternalServerError, err.Error()) - } -} - -// POST http://localhost:8080/users -// 1Melissa Raspberry -// -func (u *UserResource) createUser(request *restful.Request, response *restful.Response) { - usr := User{Id: request.PathParameter("user-id")} - err := request.ReadEntity(&usr) - if err == nil { - u.users[usr.Id] = usr - response.WriteHeaderAndEntity(http.StatusCreated, usr) - } else { - response.AddHeader("Content-Type", "text/plain") - response.WriteErrorString(http.StatusInternalServerError, err.Error()) - } -} - -// DELETE http://localhost:8080/users/1 -// -func (u *UserResource) removeUser(request *restful.Request, response *restful.Response) { - id := request.PathParameter("user-id") - delete(u.users, id) -} - -func main() { - wsContainer := restful.NewContainer() - wsContainer.Router(restful.CurlyRouter{}) - u := UserResource{map[string]User{}} - u.Register(wsContainer) - - log.Print("start listening on localhost:8080") - server := &http.Server{Addr: ":8080", Handler: wsContainer} - log.Fatal(server.ListenAndServe()) -} diff --git a/examples/restful-serve-static.go b/examples/static/restful-serve-static.go similarity index 96% rename from examples/restful-serve-static.go rename to examples/static/restful-serve-static.go index 9a946b66..2234d360 100644 --- a/examples/restful-serve-static.go +++ b/examples/static/restful-serve-static.go @@ -6,7 +6,7 @@ import ( "net/http" "path" - "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to define methods that serve static files diff --git a/examples/restful-swagger.go b/examples/swagger/restful-swagger.go similarity index 100% rename from examples/restful-swagger.go rename to examples/swagger/restful-swagger.go diff --git a/examples/template/go.mod b/examples/template/go.mod new file mode 100644 index 00000000..69ce5a61 --- /dev/null +++ b/examples/template/go.mod @@ -0,0 +1,5 @@ +module github.com/emicklei/go-restful/examples/template + +go 1.14 + +require github.com/emicklei/go-restful/v3 v3.3.3 // indirect diff --git a/examples/template/go.sum b/examples/template/go.sum new file mode 100644 index 00000000..0d611002 --- /dev/null +++ b/examples/template/go.sum @@ -0,0 +1,4 @@ +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= diff --git a/examples/home.html b/examples/template/home.html similarity index 100% rename from examples/home.html rename to examples/template/home.html diff --git a/examples/restful-html-template.go b/examples/template/restful-html-template.go similarity index 94% rename from examples/restful-html-template.go rename to examples/template/restful-html-template.go index d76d9d1e..2bb9f316 100644 --- a/examples/restful-html-template.go +++ b/examples/template/restful-html-template.go @@ -5,7 +5,7 @@ import ( "net/http" "text/template" - "github.com/emicklei/go-restful" + restful "github.com/emicklei/go-restful/v3" ) // This example shows how to serve a HTML page using the standard Go template engine. diff --git a/examples/restful-curly-router_test.go b/examples/tests/restful-curly-router_test.go similarity index 100% rename from examples/restful-curly-router_test.go rename to examples/tests/restful-curly-router_test.go diff --git a/examples/restful-route_test.go b/examples/tests/restful-route_test.go similarity index 100% rename from examples/restful-route_test.go rename to examples/tests/restful-route_test.go diff --git a/examples/restful-routefunction_test.go b/examples/tests/restful-routefunction_test.go similarity index 100% rename from examples/restful-routefunction_test.go rename to examples/tests/restful-routefunction_test.go diff --git a/examples/user-resource/go.mod b/examples/user-resource/go.mod new file mode 100644 index 00000000..e3950bcb --- /dev/null +++ b/examples/user-resource/go.mod @@ -0,0 +1,9 @@ +module github.com/emicklei/go-restful/examples/user-resource + +go 1.14 + +require ( + github.com/emicklei/go-restful-openapi/v2 v2.2.1 // indirect + github.com/emicklei/go-restful/v3 v3.3.3 // indirect + github.com/go-openapi/spec v0.19.10 // indirect +) diff --git a/examples/user-resource/go.sum b/examples/user-resource/go.sum new file mode 100644 index 00000000..667823ab --- /dev/null +++ b/examples/user-resource/go.sum @@ -0,0 +1,56 @@ +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/emicklei/go-restful v1.1.3 h1:KOKLkEASmIa2roa2xEV6WkADqyWrok5dt3TOMMHF1fE= +github.com/emicklei/go-restful v2.14.3+incompatible h1:i59XyRHAxKCVBw3vHzQlpP/+pi89wH1v1HL+RKyVgxk= +github.com/emicklei/go-restful-openapi v1.4.1 h1:SocVTIQWnXyit4dotTrwmncBAjtRaBmfcHjo3XGcCm4= +github.com/emicklei/go-restful-openapi/v2 v2.2.1 h1:9xG+IjR5kUNBNJzksOmV92DzgrBJLKCLD7uY9i5XtYI= +github.com/emicklei/go-restful-openapi/v2 v2.2.1/go.mod h1:bs67E3SEVgSmB3qDuRLqpS0NcpheqtsCCMhW2/jml1E= +github.com/emicklei/go-restful/v3 v3.0.0-rc2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.3.3 h1:2WxjFb4b+Eik8vJ1saz3jbhKnt4xaFVn3N9uU3WXfLE= +github.com/emicklei/go-restful/v3 v3.3.3/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= +github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= +github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= +github.com/go-openapi/jsonreference v0.19.4 h1:3Vw+rh13uq2JFNxgnMTGE1rnoieU9FmyE1gvnyylsYg= +github.com/go-openapi/jsonreference v0.19.4/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg= +github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= +github.com/go-openapi/spec v0.19.10 h1:pcNevfYytLaOQuTju0wm6OqcqU/E/pRwuSGigrLTI28= +github.com/go-openapi/spec v0.19.10/go.mod h1:vqK/dIdLGCosfvYsQV3WfC7N3TiZSnGY2RZKoFK7X28= +github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.6 h1:JSUbVWlaTLMhXeOMyArSUNCdroxZu2j1TcrsOV8Mj7Q= +github.com/go-openapi/swag v0.19.6/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +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/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/examples/restful-user-resource.go b/examples/user-resource/restful-user-resource.go similarity index 95% rename from examples/restful-user-resource.go rename to examples/user-resource/restful-user-resource.go index 4d1830d5..550cf065 100644 --- a/examples/restful-user-resource.go +++ b/examples/user-resource/restful-user-resource.go @@ -4,8 +4,8 @@ import ( "log" "net/http" - "github.com/emicklei/go-restful" - restfulspec "github.com/emicklei/go-restful-openapi" + restfulspec "github.com/emicklei/go-restful-openapi/v2" + restful "github.com/emicklei/go-restful/v3" "github.com/go-openapi/spec" ) @@ -125,8 +125,8 @@ func main() { restful.DefaultContainer.Add(u.WebService()) config := restfulspec.Config{ - WebServices: restful.RegisteredWebServices(), // you control what services are visible - APIPath: "/apidocs.json", + WebServices: restful.RegisteredWebServices(), // you control what services are visible + APIPath: "/apidocs.json", PostBuildSwaggerObjectHandler: enrichSwaggerObject} restful.DefaultContainer.Add(restfulspec.NewOpenAPIService(config))