Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] chi v4 + Go modules #379

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ go:
- 1.11.x

script:
- go get -d -t ./...
- go vet ./...
- 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

13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

## 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`

### 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)

Expand Down
2 changes: 1 addition & 1 deletion _examples/custom-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions _examples/custom-method/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion _examples/fileserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions _examples/graceful/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions _examples/hello-world/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions _examples/limits/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions _examples/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions _examples/rest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion _examples/router-walk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"strings"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions _examples/todos-resource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion _examples/todos-resource/todos.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"net/http"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

type todosResource struct{}
Expand Down
2 changes: 1 addition & 1 deletion _examples/todos-resource/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"net/http"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

type usersResource struct{}
Expand Down
12 changes: 6 additions & 6 deletions _examples/versions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion _examples/versions/presenter/v1/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _examples/versions/presenter/v2/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _examples/versions/presenter/v3/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions chi.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// 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
//
// 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() {
Expand All @@ -25,7 +25,7 @@
// http.ListenAndServe(":3333", r)
// }
//
// See github.com/go-chi/chi/_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
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion middleware/content_charset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/get_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion middleware/get_head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion middleware/realip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions middleware/strip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion middleware/strip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

var testContent = []byte("Hello world!")
Expand Down
2 changes: 1 addition & 1 deletion middleware/url_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"strings"

"github.com/go-chi/chi"
"github.com/go-chi/chi/v4"
)

var (
Expand Down