1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-22 20:06:21 +02:00

Merge branch 'master' of github.com:labstack/echo

This commit is contained in:
Chase Hutchins 2016-01-29 01:04:44 -08:00
commit f5a7fb7342
5 changed files with 21 additions and 10 deletions

View File

@ -7,12 +7,12 @@ import (
"fmt"
"io"
"net/http"
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"sync"
"time"
"encoding/xml"
@ -27,7 +27,6 @@ type (
middleware []MiddlewareFunc
http2 bool
maxParam *int
notFoundHandler HandlerFunc
defaultHTTPErrorHandler HTTPErrorHandler
httpErrorHandler HTTPErrorHandler
binder Binder
@ -180,8 +179,6 @@ var (
methodNotAllowedHandler = func(c *Context) error {
return NewHTTPError(http.StatusMethodNotAllowed)
}
unixEpochTime = time.Unix(0, 0)
)
// New creates an instance of Echo.
@ -232,7 +229,7 @@ func (e *Echo) SetLogPrefix(prefix string) {
e.logger.SetPrefix(prefix)
}
// SetLogOutput sets the output destination for the logger. Default value is `os.Std*`
// SetLogOutput sets the output destination for the logger. Default value is `os.Stdout`
func (e *Echo) SetLogOutput(w io.Writer) {
e.logger.SetOutput(w)
}
@ -433,7 +430,7 @@ func (e *Echo) serveFile(dir, file string, c *Context) (err error) {
d := f
// Index file
file = filepath.Join(file, indexPage)
file = path.Join(file, indexPage)
f, err = fs.Open(file)
if err != nil {
if e.autoIndex {

View File

@ -274,7 +274,7 @@ func TestEchoWebSocket(t *testing.T) {
url := fmt.Sprintf("ws://%s/ws", addr)
ws, err := websocket.Dial(url, "", origin)
if assert.NoError(t, err) {
ws.Write([]byte("test"))
ws.Write([]byte("test\n"))
defer ws.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(ws)

View File

@ -48,6 +48,18 @@ func (g *Group) Trace(path string, h Handler) {
g.echo.Trace(path, h)
}
func (g *Group) Any(path string, h Handler) {
for _, m := range methods {
g.echo.add(m, path, h)
}
}
func (g *Group) Match(methods []string, path string, h Handler) {
for _, m := range methods {
g.echo.add(m, path, h)
}
}
func (g *Group) WebSocket(path string, h HandlerFunc) {
g.echo.WebSocket(path, h)
}

View File

@ -14,6 +14,8 @@ func TestGroup(t *testing.T) {
g.Post("/", h)
g.Put("/", h)
g.Trace("/", h)
g.Any("/", h)
g.Match([]string{GET, POST}, "/", h)
g.WebSocket("/ws", h)
g.Static("/scripts", "scripts")
g.ServeDir("/scripts", "scripts")

View File

@ -35,7 +35,7 @@ SetLogPrefix sets the prefix for the logger. Default value is `echo`.
`echo#SetLogOutput(w io.Writer)`
SetLogOutput sets the output destination for the logger. Default value is `os.Std*`
SetLogOutput sets the output destination for the logger. Default value is `os.Stdout`
### Log level
@ -45,7 +45,7 @@ SetLogLevel sets the log level for the logger. Default value is `log.INFO`.
### HTTP2
`echo#HTTP(on bool)`
`echo#HTTP2(on bool)`
Enable/disable HTTP2 support.
@ -60,7 +60,7 @@ Enable/disable automatically creating an index page for the directory.
```go
e := echo.New()
e.AutoIndex(true)
e.ServerDir("/", "/Users/vr/Projects/echo")
e.ServeDir("/", "/Users/vr/Projects/echo")
e.Run(":1323")
```