From b543a3785e3a7399e04b146285b7d061eff0f1e1 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 14:34:30 -0500 Subject: [PATCH 1/6] go mod init github.com/go-chi/chi/v4 --- .travis.yml | 2 +- go.mod | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 go.mod diff --git a/.travis.yml b/.travis.yml index 44ecf0d7..a5f8d11e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ go: script: - go get -d -t ./... - go vet ./... - - go test ./... + - GO111MODULE=on go test ./... - > go_version=$(go version); if [ ${go_version:13:4} = "1.11" ]; then diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..4e9449b3 --- /dev/null +++ b/go.mod @@ -0,0 +1 @@ +module github.com/go-chi/chi/v4 From 648b5e56c4fce39f15ad82d2a6400dc02184fbde Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 14:41:38 -0500 Subject: [PATCH 2/6] go get & go vet are called automatically with Go 1.11+ & Go modules --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5f8d11e..df088acb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ go: - 1.11.x script: - - go get -d -t ./... - - go vet ./... - GO111MODULE=on go test ./... - > go_version=$(go version); From 850d53fc98453d8856a846259a21783abf0f5824 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 15:16:00 -0500 Subject: [PATCH 3/6] Travis: Build all the _example binaries --- .travis.yml | 2 +- _examples/go.mod | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 _examples/go.mod diff --git a/.travis.yml b/.travis.yml index df088acb..b53c7f8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,4 @@ script: go get -u golang.org/x/tools/cmd/goimports; goimports -d -e ./ | grep '.*' && { echo; echo "Aborting due to non-empty goimports output."; exit 1; } || :; fi - + - cd _examples && for i in */; do GO111MODULE=on go build $i/*.go; done diff --git a/_examples/go.mod b/_examples/go.mod new file mode 100644 index 00000000..e154c91f --- /dev/null +++ b/_examples/go.mod @@ -0,0 +1 @@ +module github.com/go-chi/chi/v4/_examples From 41a5dfed885e6036cb6c01648f447e654adde759 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 16:31:45 -0500 Subject: [PATCH 4/6] Update import paths to github.com/go-chi/chi/v4 --- _examples/custom-handler/main.go | 2 +- _examples/custom-method/main.go | 4 ++-- _examples/fileserver/main.go | 2 +- _examples/graceful/main.go | 4 ++-- _examples/hello-world/main.go | 4 ++-- _examples/limits/main.go | 4 ++-- _examples/logging/main.go | 4 ++-- _examples/rest/main.go | 6 +++--- _examples/router-walk/main.go | 2 +- _examples/todos-resource/main.go | 4 ++-- _examples/todos-resource/todos.go | 2 +- _examples/todos-resource/users.go | 2 +- _examples/versions/main.go | 12 ++++++------ _examples/versions/presenter/v1/article.go | 2 +- _examples/versions/presenter/v2/article.go | 2 +- _examples/versions/presenter/v3/article.go | 2 +- chi.go | 6 +++--- go.mod | 5 +++++ go.sum | 4 ++++ middleware/content_charset_test.go | 2 +- middleware/get_head.go | 2 +- middleware/get_head_test.go | 2 +- middleware/profiler.go | 2 +- middleware/realip_test.go | 2 +- middleware/strip.go | 4 ++-- middleware/strip_test.go | 2 +- middleware/throttle_test.go | 2 +- middleware/url_format.go | 2 +- 28 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 go.sum diff --git a/_examples/custom-handler/main.go b/_examples/custom-handler/main.go index 81b63dde..28f10185 100644 --- a/_examples/custom-handler/main.go +++ b/_examples/custom-handler/main.go @@ -4,7 +4,7 @@ import ( "errors" "net/http" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) type Handler func(w http.ResponseWriter, r *http.Request) error diff --git a/_examples/custom-method/main.go b/_examples/custom-method/main.go index 95555e54..bb9a83b6 100644 --- a/_examples/custom-method/main.go +++ b/_examples/custom-method/main.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" ) func init() { diff --git a/_examples/fileserver/main.go b/_examples/fileserver/main.go index 50e4b091..5194d9f9 100644 --- a/_examples/fileserver/main.go +++ b/_examples/fileserver/main.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func main() { diff --git a/_examples/graceful/main.go b/_examples/graceful/main.go index d74a2266..8f9bf452 100644 --- a/_examples/graceful/main.go +++ b/_examples/graceful/main.go @@ -8,8 +8,8 @@ import ( "os/signal" "time" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" "github.com/go-chi/valve" ) diff --git a/_examples/hello-world/main.go b/_examples/hello-world/main.go index 79e403ea..5ad1ccd7 100644 --- a/_examples/hello-world/main.go +++ b/_examples/hello-world/main.go @@ -3,8 +3,8 @@ package main import ( "net/http" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" ) func main() { diff --git a/_examples/limits/main.go b/_examples/limits/main.go index b4449a59..f5038c36 100644 --- a/_examples/limits/main.go +++ b/_examples/limits/main.go @@ -20,8 +20,8 @@ import ( "net/http" "time" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" ) func main() { diff --git a/_examples/logging/main.go b/_examples/logging/main.go index 3780fc85..745e755a 100644 --- a/_examples/logging/main.go +++ b/_examples/logging/main.go @@ -17,8 +17,8 @@ import ( "net/http" "time" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" "github.com/sirupsen/logrus" ) diff --git a/_examples/rest/main.go b/_examples/rest/main.go index 0992cab5..90d2bbe4 100644 --- a/_examples/rest/main.go +++ b/_examples/rest/main.go @@ -47,8 +47,8 @@ import ( "net/http" "strings" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" "github.com/go-chi/docgen" "github.com/go-chi/render" ) @@ -105,7 +105,7 @@ func main() { if *routes { // fmt.Println(docgen.JSONRoutesDoc(r)) fmt.Println(docgen.MarkdownRoutesDoc(r, docgen.MarkdownOpts{ - ProjectPath: "github.com/go-chi/chi", + ProjectPath: "github.com/go-chi/chi/v4", Intro: "Welcome to the chi/_examples/rest generated docs.", })) return diff --git a/_examples/router-walk/main.go b/_examples/router-walk/main.go index fcaa6bbe..ac037a02 100644 --- a/_examples/router-walk/main.go +++ b/_examples/router-walk/main.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func main() { diff --git a/_examples/todos-resource/main.go b/_examples/todos-resource/main.go index 2e3bf381..aef70b08 100644 --- a/_examples/todos-resource/main.go +++ b/_examples/todos-resource/main.go @@ -11,8 +11,8 @@ package main import ( "net/http" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/middleware" ) func main() { diff --git a/_examples/todos-resource/todos.go b/_examples/todos-resource/todos.go index c6cfbb3e..b4cbe56c 100644 --- a/_examples/todos-resource/todos.go +++ b/_examples/todos-resource/todos.go @@ -3,7 +3,7 @@ package main import ( "net/http" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) type todosResource struct{} diff --git a/_examples/todos-resource/users.go b/_examples/todos-resource/users.go index 5b00442c..b61319c7 100644 --- a/_examples/todos-resource/users.go +++ b/_examples/todos-resource/users.go @@ -3,7 +3,7 @@ package main import ( "net/http" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) type usersResource struct{} diff --git a/_examples/versions/main.go b/_examples/versions/main.go index 308f2768..c2951454 100644 --- a/_examples/versions/main.go +++ b/_examples/versions/main.go @@ -14,12 +14,12 @@ import ( "net/http" "time" - "github.com/go-chi/chi" - "github.com/go-chi/chi/_examples/versions/data" - v1 "github.com/go-chi/chi/_examples/versions/presenter/v1" - v2 "github.com/go-chi/chi/_examples/versions/presenter/v2" - v3 "github.com/go-chi/chi/_examples/versions/presenter/v3" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v4" + "github.com/go-chi/chi/v4/_examples/versions/data" + v1 "github.com/go-chi/chi/v4/_examples/versions/presenter/v1" + v2 "github.com/go-chi/chi/v4/_examples/versions/presenter/v2" + v3 "github.com/go-chi/chi/v4/_examples/versions/presenter/v3" + "github.com/go-chi/chi/v4/middleware" "github.com/go-chi/render" ) diff --git a/_examples/versions/presenter/v1/article.go b/_examples/versions/presenter/v1/article.go index ccabb5df..a31ab94c 100644 --- a/_examples/versions/presenter/v1/article.go +++ b/_examples/versions/presenter/v1/article.go @@ -3,7 +3,7 @@ package v1 import ( "net/http" - "github.com/go-chi/chi/_examples/versions/data" + "github.com/go-chi/chi/v4/_examples/versions/data" ) // Article presented in API version 1. diff --git a/_examples/versions/presenter/v2/article.go b/_examples/versions/presenter/v2/article.go index 98696428..6a5e4260 100644 --- a/_examples/versions/presenter/v2/article.go +++ b/_examples/versions/presenter/v2/article.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/go-chi/chi/_examples/versions/data" + "github.com/go-chi/chi/v4/_examples/versions/data" ) // Article presented in API version 2. diff --git a/_examples/versions/presenter/v3/article.go b/_examples/versions/presenter/v3/article.go index b627270b..f6b44c49 100644 --- a/_examples/versions/presenter/v3/article.go +++ b/_examples/versions/presenter/v3/article.go @@ -5,7 +5,7 @@ import ( "math/rand" "net/http" - "github.com/go-chi/chi/_examples/versions/data" + "github.com/go-chi/chi/v4/_examples/versions/data" ) // Article presented in API version 2. diff --git a/chi.go b/chi.go index 9962229d..192df6a8 100644 --- a/chi.go +++ b/chi.go @@ -9,8 +9,8 @@ // import ( // "net/http" // -// "github.com/go-chi/chi" -// "github.com/go-chi/chi/middleware" +// "github.com/go-chi/chi/v4" +// "github.com/go-chi/chi/v4/middleware" // ) // // func main() { @@ -25,7 +25,7 @@ // http.ListenAndServe(":3333", r) // } // -// See github.com/go-chi/chi/_examples/ for more in-depth examples. +// See github.com/go-chi/chi/v4/_examples/ for more in-depth examples. // // URL patterns allow for easy matching of path components in HTTP // requests. The matching components can then be accessed using diff --git a/go.mod b/go.mod index 4e9449b3..bdf96135 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,6 @@ module github.com/go-chi/chi/v4 + +require ( + golang.org/x/net v0.0.0-20190108155000-395948e2f546 + golang.org/x/text v0.3.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..6ace0ba1 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +golang.org/x/net v0.0.0-20190108155000-395948e2f546 h1:tkMg6+6TF2qZ/3I8fw+DiNgPSsABxdVIqWE90w8Vxzk= +golang.org/x/net v0.0.0-20190108155000-395948e2f546/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/middleware/content_charset_test.go b/middleware/content_charset_test.go index 6095cb00..effcf3ad 100644 --- a/middleware/content_charset_test.go +++ b/middleware/content_charset_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func TestContentCharset(t *testing.T) { diff --git a/middleware/get_head.go b/middleware/get_head.go index 86068a96..98665538 100644 --- a/middleware/get_head.go +++ b/middleware/get_head.go @@ -3,7 +3,7 @@ package middleware import ( "net/http" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) // GetHead automatically route undefined HEAD requests to GET handlers. diff --git a/middleware/get_head_test.go b/middleware/get_head_test.go index edfeb5b7..e72daee0 100644 --- a/middleware/get_head_test.go +++ b/middleware/get_head_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func TestGetHead(t *testing.T) { diff --git a/middleware/profiler.go b/middleware/profiler.go index 1d44b825..e81fe177 100644 --- a/middleware/profiler.go +++ b/middleware/profiler.go @@ -6,7 +6,7 @@ import ( "net/http" "net/http/pprof" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) // Profiler is a convenient subrouter used for mounting net/http/pprof. ie. diff --git a/middleware/realip_test.go b/middleware/realip_test.go index 84700735..f1ad408c 100644 --- a/middleware/realip_test.go +++ b/middleware/realip_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func TestXRealIP(t *testing.T) { diff --git a/middleware/strip.go b/middleware/strip.go index 2b8b1842..80b9796d 100644 --- a/middleware/strip.go +++ b/middleware/strip.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) // StripSlashes is a middleware that will match request paths with a trailing @@ -31,7 +31,7 @@ func StripSlashes(next http.Handler) http.Handler { // slash and redirect to the same path, less the trailing slash. // // NOTE: RedirectSlashes middleware is *incompatible* with http.FileServer, -// see https://github.com/go-chi/chi/issues/343 +// see https://github.com/go-chi/chi/v4/issues/343 func RedirectSlashes(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { var path string diff --git a/middleware/strip_test.go b/middleware/strip_test.go index 99676237..1ef24a78 100644 --- a/middleware/strip_test.go +++ b/middleware/strip_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) func TestStripSlashes(t *testing.T) { diff --git a/middleware/throttle_test.go b/middleware/throttle_test.go index 626397ee..d32961af 100644 --- a/middleware/throttle_test.go +++ b/middleware/throttle_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) var testContent = []byte("Hello world!") diff --git a/middleware/url_format.go b/middleware/url_format.go index 5749e4f3..4fea2a1b 100644 --- a/middleware/url_format.go +++ b/middleware/url_format.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v4" ) var ( From 8b462cf9a824cfbf4835f9b27a7f57d1f26c6420 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 17:26:52 -0500 Subject: [PATCH 5/6] Changelog: Implications of Go modules: Go 1.10.3+ & new import path --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cad12a88..7ae86f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## v4.0.0 (head) -- ... +- chi v4 requires Go 1.10.3+ (or Go 1.9.7+) +- chi v4 is a Go module and thus breaks the import path; use `github.com/go-chi/chi/v4` and `github.com/go-chi/chi/v4/middleware` ## v3.3.4 (2019-01-07) From 6c769c9c897d074b98befc400d1473f9ae88e653 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 8 Jan 2019 19:04:25 -0500 Subject: [PATCH 6/6] Fix examples; Document chi v3.x -> chi v4 upgrade steps --- .travis.yml | 5 +++-- CHANGELOG.md | 10 ++++++++++ _examples/go.mod | 1 - chi.go | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) delete mode 100644 _examples/go.mod diff --git a/.travis.yml b/.travis.yml index b53c7f8e..0da095b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,12 @@ go: - 1.11.x script: - - GO111MODULE=on go test ./... + - export GO111MODULE=on + - go test ./... + - for i in _examples/*/; do go build $i/*.go || exit 1; done - > go_version=$(go version); if [ ${go_version:13:4} = "1.11" ]; then go get -u golang.org/x/tools/cmd/goimports; goimports -d -e ./ | grep '.*' && { echo; echo "Aborting due to non-empty goimports output."; exit 1; } || :; fi - - cd _examples && for i in */; do GO111MODULE=on go build $i/*.go; done diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae86f7b..698b74f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ - chi v4 requires Go 1.10.3+ (or Go 1.9.7+) - chi v4 is a Go module and thus breaks the import path; use `github.com/go-chi/chi/v4` and `github.com/go-chi/chi/v4/middleware` +### Upgrading your codebase from chi v3.x to chi v4 + +Example using GNU find (`brew install find`): +``` +$ find . -type f -name '*.go' -not -path "./vendor/*" -exec sed -i 's+github.com/go-chi/chi+github.com/go-chi/chi/v4+g' {} \; +``` + +We recommend vendoring the dependencies via `GO111MODULE=on go mod vendor && GO111MODULE=on go mod tidy`. + +If your repository still pulls in the old import path, you can figure out why by running `GO111MODULE=on go mod why github.com/go-chi/chi`. ## v3.3.4 (2019-01-07) diff --git a/_examples/go.mod b/_examples/go.mod deleted file mode 100644 index e154c91f..00000000 --- a/_examples/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/go-chi/chi/v4/_examples diff --git a/chi.go b/chi.go index 192df6a8..4363adad 100644 --- a/chi.go +++ b/chi.go @@ -1,7 +1,7 @@ // // Package chi is a small, idiomatic and composable router for building HTTP services. // -// chi requires Go 1.7 or newer. +// chi v4 requires Go 1.10.3+ (or Go 1.9.7+). // // Example: // package main @@ -25,7 +25,7 @@ // http.ListenAndServe(":3333", r) // } // -// See github.com/go-chi/chi/v4/_examples/ for more in-depth examples. +// See https://github.com/go-chi/chi/tree/master/_examples for more in-depth examples. // // URL patterns allow for easy matching of path components in HTTP // requests. The matching components can then be accessed using