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 ( type (
// BasicAuthConfig defines the config for HTTP basic auth middleware. // BasicAuthConfig defines the config for HTTP basic auth middleware.
BasicAuthConfig struct { BasicAuthConfig struct {
// Validator is the function to validate basic auth credentials. // Validator is a function to validate basic auth credentials.
Validator BasicAuthValidator Validator BasicAuthValidator
} }

View File

@ -13,7 +13,7 @@ import (
type ( type (
// BodyLimitConfig defines the config for body limit middleware. // BodyLimitConfig defines the config for body limit middleware.
BodyLimitConfig struct { 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. // as `4x` or `4xB`, where x is one of the multiple from K, M, G, T or P.
Limit string `json:"limit"` Limit string `json:"limit"`
limit int64 limit int64

View File

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

View File

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

View File

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

View File

@ -19,7 +19,7 @@ import (
type ( type (
// LoggerConfig defines the config for logger middleware. // LoggerConfig defines the config for logger middleware.
LoggerConfig struct { 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 // - time_rfc3339
// - id (Request ID - Not implemented) // - id (Request ID - Not implemented)
@ -38,11 +38,11 @@ type (
// //
// Example "${remote_ip} ${status}" // Example "${remote_ip} ${status}"
// //
// Optional, with default value as `DefaultLoggerConfig.Format`. // Optional. Default value DefaultLoggerConfig.Format.
Format string Format string
// Output is the writer where logs are written. // Output is a writer where logs are written.
// Optional with default value as os.Stdout. // Optional. Default value os.Stdout.
Output io.Writer Output io.Writer
template *fasttemplate.Template template *fasttemplate.Template

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import (
type ( type (
// TrailingSlashConfig defines the config for TrailingSlash middleware. // TrailingSlashConfig defines the config for TrailingSlash middleware.
TrailingSlashConfig struct { 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. // Optional, but when provided the request is redirected using this code.
RedirectCode int RedirectCode int
} }

View File

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