diff --git a/echo.go b/echo.go index c61d9688..d6fded1b 100644 --- a/echo.go +++ b/echo.go @@ -474,5 +474,9 @@ func (binder) Bind(r engine.Request, i interface{}) (err error) { } func handlerName(h Handler) string { - return runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name() + t := reflect.ValueOf(h).Type() + if t.Kind() == reflect.Func { + return runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name() + } + return t.String() } diff --git a/engine/standard/server.go b/engine/standard/server.go index 55b0a4bc..8acfa8a5 100644 --- a/engine/standard/server.go +++ b/engine/standard/server.go @@ -96,7 +96,8 @@ func (s *Server) Start() { // Response res := s.pool.response.Get().(*Response) resHdr := s.pool.header.Get().(*Header) - res.reset(w, reqHdr) + resHdr.reset(w.Header()) + res.reset(w, resHdr) s.handler(req, res) diff --git a/handler/static.go b/handler/static.go index b40f4613..a7995ea1 100644 --- a/handler/static.go +++ b/handler/static.go @@ -12,11 +12,18 @@ import ( type ( Static struct { Root string - Browse bool Index string + Browse bool } ) +func NewStatic(root string) *Static { + return &Static{ + Root: root, + Index: "index.html", + } +} + func (s Static) Handle(c echo.Context) error { fs := http.Dir(s.Root) file := c.P(0) @@ -49,9 +56,9 @@ func (s Static) Handle(c echo.Context) error { } // Create a directory index - w := c.Response() - w.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8) - if _, err = fmt.Fprintf(w, "
\n"); err != nil { + res := c.Response() + res.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8) + if _, err = fmt.Fprintf(res, "\n") return err } return echo.ErrNotFound\n"); err != nil { return err } for _, d := range dirs { @@ -61,11 +68,11 @@ func (s Static) Handle(c echo.Context) error { color = "#e91e63" name += "/" } - if _, err = fmt.Fprintf(w, "%s\n", name, color, name); err != nil { + if _, err = fmt.Fprintf(res, "%s\n", name, color, name); err != nil { return err } } - _, err = fmt.Fprintf(w, "\n") + _, err = fmt.Fprintf(res, "