mirror of
https://github.com/labstack/echo.git
synced 2024-12-28 21:08:39 +02:00
Fixed build
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
f96c973a25
commit
c7531df815
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ _test
|
||||
vendor
|
||||
.idea
|
||||
*.iml
|
||||
*.out
|
||||
|
2
Makefile
2
Makefile
@ -5,6 +5,6 @@ dependency:
|
||||
test:
|
||||
echo "" > coverage.txt
|
||||
for d in $(shell go list ./... | grep -v vendor); do \
|
||||
go test -race -coverprofile=profile.out -covermode=atomic $$d; \
|
||||
go test -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \
|
||||
[ -f profile.out ] && cat profile.out >> coverage.txt && rm profile.out; \
|
||||
done
|
||||
|
@ -2,6 +2,7 @@ package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -77,19 +78,23 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
}
|
||||
p, err = echo.PathUnescape(p)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
name := filepath.Join(config.Root, path.Clean("/"+p)) // "/"+ for security
|
||||
|
||||
fi, err := os.Stat(name)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if config.HTML5 && path.Ext(p) != "" {
|
||||
return c.File(filepath.Join(config.Root, config.Index))
|
||||
if err = next(c); err != nil {
|
||||
if he, ok := err.(*echo.HTTPError); ok {
|
||||
if config.HTML5 && he.Code == http.StatusNotFound {
|
||||
return c.File(filepath.Join(config.Root, config.Index))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
return next(c)
|
||||
}
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
@ -103,7 +108,7 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
if os.IsNotExist(err) {
|
||||
return next(c)
|
||||
}
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
return c.File(index)
|
||||
@ -114,20 +119,20 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func listDir(name string, res *echo.Response) error {
|
||||
func listDir(name string, res *echo.Response) (err error) {
|
||||
dir, err := os.Open(name)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
dirs, err := dir.Readdir(-1)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
||||
// Create a directory index
|
||||
res.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
|
||||
if _, err = fmt.Fprintf(res, "<pre>\n"); err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
for _, d := range dirs {
|
||||
name := d.Name()
|
||||
@ -137,9 +142,9 @@ func listDir(name string, res *echo.Response) error {
|
||||
name += "/"
|
||||
}
|
||||
if _, err = fmt.Fprintf(res, "<a href=\"%s\" style=\"color: %s;\">%s</a>\n", name, color, name); err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
}
|
||||
_, err = fmt.Fprintf(res, "</pre>\n")
|
||||
return err
|
||||
return
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ func (r *Response) WriteHeader(code int) {
|
||||
r.context.Logger().Warn("response already committed")
|
||||
return
|
||||
}
|
||||
// for _, fn := range r.beforeFuncs {
|
||||
// fn(r.context)
|
||||
// }
|
||||
for _, fn := range r.beforeFuncs {
|
||||
fn(r.context)
|
||||
}
|
||||
r.Status = code
|
||||
r.Writer.WriteHeader(code)
|
||||
r.Committed = true
|
||||
|
Loading…
Reference in New Issue
Block a user