mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Fixed response header and get handler name
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
d14b8f5ba4
commit
e91717552f
6
echo.go
6
echo.go
@ -474,5 +474,9 @@ func (binder) Bind(r engine.Request, i interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlerName(h Handler) string {
|
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()
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,8 @@ func (s *Server) Start() {
|
|||||||
// Response
|
// Response
|
||||||
res := s.pool.response.Get().(*Response)
|
res := s.pool.response.Get().(*Response)
|
||||||
resHdr := s.pool.header.Get().(*Header)
|
resHdr := s.pool.header.Get().(*Header)
|
||||||
res.reset(w, reqHdr)
|
resHdr.reset(w.Header())
|
||||||
|
res.reset(w, resHdr)
|
||||||
|
|
||||||
s.handler(req, res)
|
s.handler(req, res)
|
||||||
|
|
||||||
|
@ -12,11 +12,18 @@ import (
|
|||||||
type (
|
type (
|
||||||
Static struct {
|
Static struct {
|
||||||
Root string
|
Root string
|
||||||
Browse bool
|
|
||||||
Index string
|
Index string
|
||||||
|
Browse bool
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewStatic(root string) *Static {
|
||||||
|
return &Static{
|
||||||
|
Root: root,
|
||||||
|
Index: "index.html",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s Static) Handle(c echo.Context) error {
|
func (s Static) Handle(c echo.Context) error {
|
||||||
fs := http.Dir(s.Root)
|
fs := http.Dir(s.Root)
|
||||||
file := c.P(0)
|
file := c.P(0)
|
||||||
@ -49,9 +56,9 @@ func (s Static) Handle(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a directory index
|
// Create a directory index
|
||||||
w := c.Response()
|
res := c.Response()
|
||||||
w.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8)
|
res.Header().Set(echo.ContentType, echo.TextHTMLCharsetUTF8)
|
||||||
if _, err = fmt.Fprintf(w, "<pre>\n"); err != nil {
|
if _, err = fmt.Fprintf(res, "<pre>\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
@ -61,11 +68,11 @@ func (s Static) Handle(c echo.Context) error {
|
|||||||
color = "#e91e63"
|
color = "#e91e63"
|
||||||
name += "/"
|
name += "/"
|
||||||
}
|
}
|
||||||
if _, err = fmt.Fprintf(w, "<a href=\"%s\" style=\"color: %s;\">%s</a>\n", name, color, name); err != nil {
|
if _, err = fmt.Fprintf(res, "<a href=\"%s\" style=\"color: %s;\">%s</a>\n", name, color, name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = fmt.Fprintf(w, "</pre>\n")
|
_, err = fmt.Fprintf(res, "</pre>\n")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return echo.ErrNotFound
|
return echo.ErrNotFound
|
||||||
|
Loading…
Reference in New Issue
Block a user