1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Updated docs, changes to static middleware config

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-05-10 11:52:04 -07:00
parent 799c6cff2a
commit 1afaa6ec0b
11 changed files with 41 additions and 44 deletions

View File

@ -9,7 +9,7 @@ import (
type (
// BasicAuthConfig defines the config for HTTP basic auth middleware.
BasicAuthConfig struct {
// Validator is the function to validate basic auth credentials.
// Validator is a function to validate basic auth credentials.
Validator BasicAuthValidator
}

View File

@ -13,7 +13,7 @@ import (
type (
// BodyLimitConfig defines the config for body limit middleware.
BodyLimitConfig struct {
// Limit is the maximum allowed size for a request body, it can be specified
// Maximum allowed size for a request body, it can be specified
// as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.
Limit string `json:"limit"`
limit int64

View File

@ -15,8 +15,8 @@ import (
type (
// GzipConfig defines the config for gzip middleware.
GzipConfig struct {
// Level is the gzip level.
// Optional, with default value as -1.
// Gzip compression level.
// Optional. Default value -1.
Level int
}

View File

@ -12,34 +12,34 @@ type (
// CORSConfig defines the config for CORS middleware.
CORSConfig struct {
// AllowOrigin defines a list of origins that may access the resource.
// Optional, with default value as []string{"*"}.
// Optional. Default value []string{"*"}.
AllowOrigins []string
// AllowMethods defines a list methods allowed when accessing the resource.
// This is used in response to a preflight request.
// Optional, with default value as `DefaultCORSConfig.AllowMethods`.
// Optional. Default value DefaultCORSConfig.AllowMethods.
AllowMethods []string
// AllowHeaders defines a list of request headers that can be used when
// making the actual request. This in response to a preflight request.
// Optional, with default value as []string{}.
// Optional. Default value []string{}.
AllowHeaders []string
// AllowCredentials indicates whether or not the response to the request
// can be exposed when the credentials flag is true. When used as part of
// a response to a preflight request, this indicates whether or not the
// actual request can be made using credentials.
// Optional, with default value as false.
// Optional. Default value false.
AllowCredentials bool
// ExposeHeaders defines a whitelist headers that clients are allowed to
// access.
// Optional, with default value as []string{}.
// Optional. Default value []string{}.
ExposeHeaders []string
// MaxAge indicates how long (in seconds) the results of a preflight request
// can be cached.
// Optional, with default value as 0.
// Optional. Default value 0.
MaxAge int
}
)

View File

@ -11,21 +11,20 @@ import (
type (
// JWTConfig defines the config for JWT auth middleware.
JWTConfig struct {
// SigningKey is the key to validate token.
// Signing key to validate token.
// Required.
SigningKey []byte
// SigningMethod is used to check token signing method.
// Optional, with default value as `HS256`.
// Signing method, used to check token signing method.
// Optional. Default value HS256.
SigningMethod string
// ContextKey is the key to be used for storing user information from the
// token into context.
// Optional, with default value as `user`.
// Context key to store user information from the token into context.
// Optional. Default value "user".
ContextKey string
// Extractor is a function that extracts token from the request.
// Optional, with default values as `JWTFromHeader`.
// Optional. Default value JWTFromHeader.
Extractor JWTExtractor
}

View File

@ -19,7 +19,7 @@ import (
type (
// LoggerConfig defines the config for logger middleware.
LoggerConfig struct {
// Format is the log format which can be constructed using the following tags:
// Log format which can be constructed using the following tags:
//
// - time_rfc3339
// - id (Request ID - Not implemented)
@ -38,11 +38,11 @@ type (
//
// Example "${remote_ip} ${status}"
//
// Optional, with default value as `DefaultLoggerConfig.Format`.
// Optional. Default value DefaultLoggerConfig.Format.
Format string
// Output is the writer where logs are written.
// Optional with default value as os.Stdout.
// Output is a writer where logs are written.
// Optional. Default value os.Stdout.
Output io.Writer
template *fasttemplate.Template

View File

@ -8,11 +8,11 @@ type (
// MethodOverrideConfig defines the config for method override middleware.
MethodOverrideConfig struct {
// Getter is a function that gets overridden method from the request.
// Optional. Default values MethodFromHeader(echo.HeaderXHTTPMethodOverride).
Getter MethodOverrideGetter
}
// MethodOverrideGetter is a function that gets overridden method from the request
// Optional, with default values as `MethodFromHeader(echo.HeaderXHTTPMethodOverride)`.
MethodOverrideGetter func(echo.Context) string
)

View File

@ -11,17 +11,17 @@ import (
type (
// RecoverConfig defines the config for recover middleware.
RecoverConfig struct {
// StackSize is the stack size to be printed.
// Optional, with default value as 4 KB.
// Size of the stack to be printed.
// Optional. Default value 4KB.
StackSize int
// DisableStackAll disables formatting stack traces of all other goroutines
// into buffer after the trace for the current goroutine.
// Optional, with default value as false.
// Optional. Default value false.
DisableStackAll bool
// DisablePrintStack disables printing stack trace.
// Optional, with default value as false.
// Optional. Default value as false.
DisablePrintStack bool
}
)

View File

@ -11,12 +11,12 @@ type (
SecureConfig struct {
// XSSProtection provides protection against cross-site scripting attack (XSS)
// by setting the `X-XSS-Protection` header.
// Optional, with default value as `1; mode=block`.
// Optional. Default value "1; mode=block".
XSSProtection string
// ContentTypeNosniff provides protection against overriding Content-Type
// header by setting the `X-Content-Type-Options` header.
// Optional, with default value as "nosniff".
// Optional. Default value "nosniff".
ContentTypeNosniff string
// XFrameOptions can be used to indicate whether or not a browser should
@ -24,7 +24,7 @@ type (
// Sites can use this to avoid clickjacking attacks, by ensuring that their
// content is not embedded into other sites.provides protection against
// clickjacking.
// Optional, with default value as "SAMEORIGIN".
// Optional. Default value "SAMEORIGIN".
// Possible values:
// `SAMEORIGIN` - The page can only be displayed in a frame on the same origin as the page itself.
// `DENY` - The page cannot be displayed in a frame, regardless of the site attempting to do so.
@ -35,20 +35,20 @@ type (
// long (in seconds) browsers should remember that this site is only to
// be accessed using HTTPS. This reduces your exposure to some SSL-stripping
// man-in-the-middle (MITM) attacks.
// Optional, with default value as 0.
// Optional. Default value 0.
HSTSMaxAge int
// HSTSExcludeSubdomains won't include subdomains tag in the `Strict Transport Security`
// header, excluding all subdomains from security policy. It has no effect
// unless HSTSMaxAge is set to a non-zero value.
// Optional, with default value as false.
// Optional. Default value false.
HSTSExcludeSubdomains bool
// ContentSecurityPolicy sets the `Content-Security-Policy` header providing
// security against cross-site scripting (XSS), clickjacking and other code
// injection attacks resulting from execution of malicious content in the
// trusted web page context.
// Optional, with default value as "".
// Optional. Default value "".
ContentSecurityPolicy string
}
)

View File

@ -7,7 +7,7 @@ import (
type (
// TrailingSlashConfig defines the config for TrailingSlash middleware.
TrailingSlashConfig struct {
// RedirectCode is the status code used when redirecting the request.
// Status code to be used when redirecting the request.
// Optional, but when provided the request is redirected using this code.
RedirectCode int
}

View File

@ -12,17 +12,16 @@ import (
type (
// StaticConfig defines the config for static middleware.
StaticConfig struct {
// Root is the directory from where the static content is served.
// Root directory from where the static content is served.
// Required.
Root string `json:"root"`
// Index is the list of index files to be searched and used when serving
// a directory.
// Optional, with default value as []string{"index.html"}.
Index []string `json:"index"`
// Index file for serving a directory.
// Optional. Default value "index.html".
Index string `json:"index"`
// Browse is a flag to enable/disable directory browsing.
// Optional, with default value as false.
// Enable/disable directory browsing.
// Optional. Default value false.
Browse bool `json:"browse"`
}
)
@ -30,7 +29,7 @@ type (
var (
// DefaultStaticConfig is the default static middleware config.
DefaultStaticConfig = StaticConfig{
Index: []string{"index.html"},
Index: "index.html",
Browse: false,
}
)
@ -47,7 +46,7 @@ func Static(root string) echo.MiddlewareFunc {
// See `Static()`.
func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
// Defaults
if config.Index == nil {
if config.Index == "" {
config.Index = DefaultStaticConfig.Index
}
@ -77,8 +76,7 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
d := f
// Index file
// TODO: search all files
file = path.Join(file, config.Index[0])
file = path.Join(file, config.Index)
f, err = fs.Open(file)
if err == nil {
// Index file