1
0
mirror of https://github.com/labstack/echo.git synced 2025-11-29 22:48:07 +02:00

Defaults for middleware config

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-03-31 16:30:19 -07:00
parent 1b3197a149
commit 1113413441
5 changed files with 39 additions and 8 deletions

View File

@@ -9,17 +9,19 @@ import (
)
type (
// StaticConfig defines config for static middleware.
// StaticConfig defines the config for static middleware.
StaticConfig struct {
// Root is the directory from where the static content is served.
// Optional with default value as `DefaultStaticConfig.Root`.
Root string `json:"root"`
// Index is the list of index files to be searched and used when serving
// a directory.
// Default value is `[]string{"index.html"}`.
// Optional with default value as `DefaultStaticConfig.Index`.
Index []string `json:"index"`
// Browse is a flag to enable/disable directory browsing.
// Required.
Browse bool `json:"browse"`
}
)
@@ -44,6 +46,11 @@ func Static(root string) echo.MiddlewareFunc {
// StaticFromConfig returns a static middleware from config.
// See `Static()`.
func StaticFromConfig(config StaticConfig) echo.MiddlewareFunc {
// Defaults
if config.Index == nil {
config.Index = DefaultStaticConfig.Index
}
return func(next echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
fs := http.Dir(config.Root)