1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Introduced Go module support as v4, removed obsolete CloseNotifier() mechanism

This reintroduces support for Go modules, as v4.

CloseNotifier() is removed as it has been obsoleted, see https://golang.org/doc/go1.11#net/http

It was already NOT working (not sending signals) as of 1.11 the functionality was gone, we merely
deleted the functions that exposed it. If anyone still relies on it they should migrate to using
`c.Request().Context().Done()` instead.

Closes #1268, #1255
This commit is contained in:
Alex Ungur 2019-01-30 12:56:56 +02:00
parent 282a44d4ad
commit 6d9e043284
45 changed files with 107 additions and 94 deletions

View File

@ -4,12 +4,26 @@
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/labstack/echo)
[![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo)
[![Build Status](http://img.shields.io/travis/labstack/echo.svg?style=flat-square)](https://travis-ci.org/labstack/echo)
[![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo)
[![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo)
[![Join the chat at https://gitter.im/labstack/echo](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/labstack/echo)
[![Forum](https://img.shields.io/badge/community-forum-00afd1.svg?style=flat-square)](https://forum.labstack.com)
[![Twitter](https://img.shields.io/badge/twitter-@labstack-55acee.svg?style=flat-square)](https://twitter.com/labstack)
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE)
## Supported Go versions
As of version 4.0.0, Echo is available as a [Go module](https://github.com/golang/go/wiki/Modules).
Therefore a Go version capable of understanding /vN suffixed imports is required:
- 1.9.7+
- 1.10.3+
- 1.11+
Any of these versions will allow you to import Echo as `github.com/labstack/echo/v4` which is the recommended
way of using Echo going forward.
For older versions, please use the latest v3 tag.
## Feature Overview
- Optimized HTTP router which smartly prioritize routes
@ -44,8 +58,8 @@ package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
@ -90,6 +104,7 @@ func hello(c echo.Context) error {
- Improve/fix documentation
## Credits
- [Vishal Rana](https://github.com/vishr) - Author
- [Nitin Rana](https://github.com/nr17) - Consultant
- [Contributors](https://github.com/labstack/echo/graphs/contributors)

View File

@ -8,8 +8,8 @@ Example:
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
// Handler
@ -221,7 +221,7 @@ const (
const (
// Version of Echo
Version = "3.3.11-dev"
Version = "4.0.0"
website = "https://echo.labstack.com"
// http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo
banner = `

13
go.mod Normal file
View File

@ -0,0 +1,13 @@
module github.com/labstack/echo/v4
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/labstack/gommon v0.2.8
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/stretchr/testify v1.3.0
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4
golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc // indirect
)

23
go.sum Normal file
View File

@ -0,0 +1,23 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
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=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8=
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw=
golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664 h1:YbZJ76lQ1BqNhVe7dKTSB67wDrc2VPRR75IyGyyPDX8=
golang.org/x/crypto v0.0.0-20190130090550-b01c7a725664/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc h1:WiYx1rIFmx8c0mXAFtv5D/mHyKe1+jmuP7PViuwqwuQ=
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

View File

@ -5,7 +5,7 @@ import (
"strconv"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -8,7 +8,7 @@ import (
"net"
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (
@ -105,7 +105,3 @@ func (w *bodyDumpResponseWriter) Flush() {
func (w *bodyDumpResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return w.ResponseWriter.(http.Hijacker).Hijack()
}
func (w *bodyDumpResponseWriter) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}

View File

@ -8,7 +8,7 @@ import (
"strings"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -5,7 +5,7 @@ import (
"io"
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/bytes"
)

View File

@ -7,7 +7,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -9,7 +9,7 @@ import (
"net/http"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (
@ -116,7 +116,3 @@ func (w *gzipResponseWriter) Flush() {
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return w.ResponseWriter.(http.Hijacker).Hijack()
}
func (w *gzipResponseWriter) CloseNotify() <-chan bool {
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
}

View File

@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -5,7 +5,7 @@ import (
"strconv"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/random"
)

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/random"
"github.com/stretchr/testify/assert"
)

View File

@ -7,7 +7,7 @@ import (
"strings"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -5,7 +5,7 @@ import (
"net/http"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/color"
"github.com/valyala/fasttemplate"
)

View File

@ -12,7 +12,7 @@ import (
"time"
"unsafe"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -3,7 +3,7 @@ package middleware
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -5,7 +5,7 @@ import (
"strconv"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -13,7 +13,7 @@ import (
"sync/atomic"
"time"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
// TODO: Handle TLS proxy
@ -37,11 +37,11 @@ type (
// "/users/*/orders/*": "/user/$1/order/$2",
Rewrite map[string]string
// Context key to store selected ProxyTarget into context.
// Context key to store selected ProxyTarget into context.
// Optional. Default value "target".
ContextKey string
// To customize the transport to remote.
// To customize the transport to remote.
// Examples: If custom TLS certificates are required.
Transport http.RoundTripper

View File

@ -7,7 +7,7 @@ import (
"net/http"
"net/http/httputil"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
func proxyHTTP(tgt *ProxyTarget, c echo.Context, config ProxyConfig) http.Handler {

View File

@ -3,9 +3,10 @@
package middleware
import (
"github.com/labstack/echo"
"net/http"
"net/http/httputil"
"github.com/labstack/echo/v4"
)
func proxyHTTP(t *ProxyTarget, c echo.Context, config ProxyConfig) http.Handler {

View File

@ -8,7 +8,7 @@ import (
"net/url"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
@ -42,10 +42,10 @@ func TestProxy_1_11(t *testing.T) {
e := echo.New()
e.Use(Proxy(rb))
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := newCloseNotifyRecorder()
rec := httptest.NewRecorder()
// Remote unreachable
rec = newCloseNotifyRecorder()
rec = httptest.NewRecorder()
req.URL.Path = "/api/users"
e.ServeHTTP(rec, req)
assert.Equal(t, "/api/users", req.URL.Path)

View File

@ -7,32 +7,10 @@ import (
"net/url"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)
type (
closeNotifyRecorder struct {
*httptest.ResponseRecorder
closed chan bool
}
)
func newCloseNotifyRecorder() *closeNotifyRecorder {
return &closeNotifyRecorder{
httptest.NewRecorder(),
make(chan bool, 1),
}
}
func (c *closeNotifyRecorder) close() {
c.closed <- true
}
func (c *closeNotifyRecorder) CloseNotify() <-chan bool {
return c.closed
}
func TestProxy(t *testing.T) {
// Setup
t1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -71,7 +49,7 @@ func TestProxy(t *testing.T) {
e := echo.New()
e.Use(Proxy(rb))
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := newCloseNotifyRecorder()
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
body := rec.Body.String()
expected := map[string]bool{
@ -92,11 +70,11 @@ func TestProxy(t *testing.T) {
rrb := NewRoundRobinBalancer(targets)
e = echo.New()
e.Use(Proxy(rrb))
rec = newCloseNotifyRecorder()
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
body = rec.Body.String()
assert.Equal(t, "target 1", body)
rec = newCloseNotifyRecorder()
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
body = rec.Body.String()
assert.Equal(t, "target 2", body)
@ -138,6 +116,6 @@ func TestProxy(t *testing.T) {
e = echo.New()
e.Use(contextObserver)
e.Use(Proxy(rrb1))
rec = newCloseNotifyRecorder()
rec = httptest.NewRecorder()
e.ServeHTTP(rec, req)
}

View File

@ -4,7 +4,7 @@ import (
"fmt"
"runtime"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -3,7 +3,7 @@ package middleware
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
// RedirectConfig defines the config for Redirect middleware.

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -1,7 +1,7 @@
package middleware
import (
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/random"
)

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -4,7 +4,7 @@ import (
"regexp"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -3,7 +3,7 @@ package middleware
import (
"fmt"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -1,7 +1,7 @@
package middleware
import (
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
type (

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/bytes"
)
@ -76,7 +76,7 @@ const html = `
transition: opacity 0.25s;
}
li span {
color: #707070;
color: #707070;
font-size: 12px;
}
li a:hover {

View File

@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
)

View File

@ -91,15 +91,6 @@ func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return r.Writer.(http.Hijacker).Hijack()
}
// CloseNotify implements the http.CloseNotifier interface to allow detecting
// when the underlying connection has gone away.
// This mechanism can be used to cancel long operations on the server if the
// client has disconnected before the response is ready.
// See [http.CloseNotifier](https://golang.org/pkg/net/http/#CloseNotifier)
func (r *Response) CloseNotify() <-chan bool {
return r.Writer.(http.CloseNotifier).CloseNotify()
}
func (r *Response) reset(w http.ResponseWriter) {
r.beforeFuncs = nil
r.afterFuncs = nil