mirror of
https://github.com/labstack/echo.git
synced 2025-05-13 22:06:36 +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
|
vendor
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
*.out
|
||||||
|
2
Makefile
2
Makefile
@ -5,6 +5,6 @@ dependency:
|
|||||||
test:
|
test:
|
||||||
echo "" > coverage.txt
|
echo "" > coverage.txt
|
||||||
for d in $(shell go list ./... | grep -v vendor); do \
|
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; \
|
[ -f profile.out ] && cat profile.out >> coverage.txt && rm profile.out; \
|
||||||
done
|
done
|
||||||
|
@ -2,6 +2,7 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -77,19 +78,23 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
|||||||
}
|
}
|
||||||
p, err = echo.PathUnescape(p)
|
p, err = echo.PathUnescape(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
name := filepath.Join(config.Root, path.Clean("/"+p)) // "/"+ for security
|
name := filepath.Join(config.Root, path.Clean("/"+p)) // "/"+ for security
|
||||||
|
|
||||||
fi, err := os.Stat(name)
|
fi, err := os.Stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if config.HTML5 && path.Ext(p) != "" {
|
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 c.File(filepath.Join(config.Root, config.Index))
|
||||||
}
|
}
|
||||||
return next(c)
|
|
||||||
}
|
}
|
||||||
return err
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
@ -103,7 +108,7 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.File(index)
|
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)
|
dir, err := os.Open(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
dirs, err := dir.Readdir(-1)
|
dirs, err := dir.Readdir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a directory index
|
// Create a directory index
|
||||||
res.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
|
res.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
|
||||||
if _, err = fmt.Fprintf(res, "<pre>\n"); err != nil {
|
if _, err = fmt.Fprintf(res, "<pre>\n"); err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
name := d.Name()
|
name := d.Name()
|
||||||
@ -137,9 +142,9 @@ func listDir(name string, res *echo.Response) error {
|
|||||||
name += "/"
|
name += "/"
|
||||||
}
|
}
|
||||||
if _, err = fmt.Fprintf(res, "<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 = fmt.Fprintf(res, "</pre>\n")
|
_, 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")
|
r.context.Logger().Warn("response already committed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// for _, fn := range r.beforeFuncs {
|
for _, fn := range r.beforeFuncs {
|
||||||
// fn(r.context)
|
fn(r.context)
|
||||||
// }
|
}
|
||||||
r.Status = code
|
r.Status = code
|
||||||
r.Writer.WriteHeader(code)
|
r.Writer.WriteHeader(code)
|
||||||
r.Committed = true
|
r.Committed = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user