mirror of
https://github.com/labstack/echo.git
synced 2025-01-24 03:16:14 +02:00
Clean old Go versions
This commit is contained in:
parent
60f88a7a1c
commit
af1bfd5397
25
echo.go
25
echo.go
@ -38,6 +38,7 @@ package echo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
stdContext "context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -45,6 +46,7 @@ import (
|
||||
stdLog "log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -678,6 +680,24 @@ func (e *Echo) StartServer(s *http.Server) (err error) {
|
||||
return s.Serve(e.TLSListener)
|
||||
}
|
||||
|
||||
// Close immediately stops the server.
|
||||
// It internally calls `http.Server#Close()`.
|
||||
func (e *Echo) Close() error {
|
||||
if err := e.TLSServer.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.Server.Close()
|
||||
}
|
||||
|
||||
// Shutdown stops server the gracefully.
|
||||
// It internally calls `http.Server#Shutdown()`.
|
||||
func (e *Echo) Shutdown(ctx stdContext.Context) error {
|
||||
if err := e.TLSServer.Shutdown(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.Server.Shutdown(ctx)
|
||||
}
|
||||
|
||||
// NewHTTPError creates a new HTTPError instance.
|
||||
func NewHTTPError(code int, message ...interface{}) *HTTPError {
|
||||
he := &HTTPError{Code: code, Message: http.StatusText(code)}
|
||||
@ -729,6 +749,11 @@ func handlerName(h HandlerFunc) string {
|
||||
return t.String()
|
||||
}
|
||||
|
||||
// PathUnescape is wraps `url.PathUnescape`
|
||||
func PathUnescape(s string) (string, error) {
|
||||
return url.PathUnescape(s)
|
||||
}
|
||||
|
||||
// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
|
||||
// connections. It's used by ListenAndServe and ListenAndServeTLS so
|
||||
// dead TCP connections (e.g. closing laptop mid-download) eventually
|
||||
|
@ -1,25 +0,0 @@
|
||||
// +build go1.8
|
||||
|
||||
package echo
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
)
|
||||
|
||||
// Close immediately stops the server.
|
||||
// It internally calls `http.Server#Close()`.
|
||||
func (e *Echo) Close() error {
|
||||
if err := e.TLSServer.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.Server.Close()
|
||||
}
|
||||
|
||||
// Shutdown stops server the gracefully.
|
||||
// It internally calls `http.Server#Shutdown()`.
|
||||
func (e *Echo) Shutdown(ctx stdContext.Context) error {
|
||||
if err := e.TLSServer.Shutdown(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return e.Server.Shutdown(ctx)
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
// +build go1.8
|
||||
|
||||
package echo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEchoClose(t *testing.T) {
|
||||
e := New()
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
errCh <- e.Start(":0")
|
||||
}()
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
if err := e.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.NoError(t, e.Close())
|
||||
|
||||
err := <-errCh
|
||||
assert.Equal(t, err.Error(), "http: Server closed")
|
||||
}
|
43
echo_test.go
43
echo_test.go
@ -2,6 +2,7 @@ package echo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
stdContext "context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@ -461,3 +462,45 @@ func TestHTTPError(t *testing.T) {
|
||||
})
|
||||
assert.Equal(t, "code=400, message=map[code:12]", err.Error())
|
||||
}
|
||||
|
||||
func TestEchoClose(t *testing.T) {
|
||||
e := New()
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
errCh <- e.Start(":0")
|
||||
}()
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
if err := e.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.NoError(t, e.Close())
|
||||
|
||||
err := <-errCh
|
||||
assert.Equal(t, err.Error(), "http: Server closed")
|
||||
}
|
||||
|
||||
func TestEchoShutdown(t *testing.T) {
|
||||
e := New()
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
errCh <- e.Start(":0")
|
||||
}()
|
||||
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
if err := e.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
assert.NoError(t, e.Shutdown(ctx))
|
||||
|
||||
err := <-errCh
|
||||
assert.Equal(t, err.Error(), "http: Server closed")
|
||||
}
|
||||
|
12
util_go17.go
12
util_go17.go
@ -1,12 +0,0 @@
|
||||
// +build go1.7, !go1.8
|
||||
|
||||
package echo
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// PathUnescape is wraps `url.QueryUnescape`
|
||||
func PathUnescape(s string) (string, error) {
|
||||
return url.QueryUnescape(s)
|
||||
}
|
10
util_go18.go
10
util_go18.go
@ -1,10 +0,0 @@
|
||||
// +build go1.8
|
||||
|
||||
package echo
|
||||
|
||||
import "net/url"
|
||||
|
||||
// PathUnescape is wraps `url.PathUnescape`
|
||||
func PathUnescape(s string) (string, error) {
|
||||
return url.PathUnescape(s)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user