Skip to content

Commit

Permalink
Fixed default options for static
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Feb 20, 2016
1 parent b97a2c5 commit 4f6fd97
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions middleware/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ type (
func Static(root string, options ...*StaticOptions) echo.MiddlewareFunc {
return func(next echo.Handler) echo.Handler {
// Default options
opts := &StaticOptions{Index: "index.html"}
opts := new(StaticOptions)
if len(options) > 0 {
opts = options[0]
}
if opts.Index == "" {
opts.Index = "index.html"
}

return echo.HandlerFunc(func(c echo.Context) error {
fs := http.Dir(root)
file := c.Request().URI()
file := path.Clean(c.Request().URL().Path())
f, err := fs.Open(file)
if err != nil {
return next.Handle(c)
Expand Down

0 comments on commit 4f6fd97

Please sign in to comment.