Skip to content

Commit

Permalink
Clean old Go versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrestein authored and vishr committed Apr 3, 2018
1 parent 60f88a7 commit af1bfd5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 77 deletions.
25 changes: 25 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ package echo

import (
"bytes"
stdContext "context"
"crypto/tls"
"errors"
"fmt"
"io"
stdLog "log"
"net"
"net/http"
"net/url"
"path"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions echo_go1.8.go

This file was deleted.

30 changes: 0 additions & 30 deletions echo_go1.8_test.go

This file was deleted.

43 changes: 43 additions & 0 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package echo

import (
"bytes"
stdContext "context"
"errors"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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 changes: 0 additions & 12 deletions util_go17.go

This file was deleted.

10 changes: 0 additions & 10 deletions util_go18.go

This file was deleted.

0 comments on commit af1bfd5

Please sign in to comment.