1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-05 00:58:47 +02:00

Default bool config as false for middleware

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-04-05 18:57:57 -07:00
parent 28fb57585b
commit adad28012c
4 changed files with 19 additions and 18 deletions

View File

@ -16,7 +16,7 @@ type (
// GzipConfig defines the config for gzip middleware. // GzipConfig defines the config for gzip middleware.
GzipConfig struct { GzipConfig struct {
// Level is the gzip level. // Level is the gzip level.
// Optional with default value as `DefaultGzipConfig.Level`. // Optional with default value as -1.
Level int Level int
} }

View File

@ -34,7 +34,7 @@ type (
Format string Format string
// Output is the writer where logs are written. // Output is the writer where logs are written.
// Optional with default value as `DefaultLoggerConfig.Output`. // Optional with default value as os.Stdout.
Output io.Writer Output io.Writer
template *fasttemplate.Template template *fasttemplate.Template

View File

@ -12,26 +12,26 @@ 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. // StackSize is the stack size to be printed.
// Optional with default value as `DefaultRecoverConfig.StackSize`. // Optional with default value as 4 KB.
StackSize int StackSize int
// StackAll is a flag to format stack traces of all other goroutines into // DisableStackAll disables formatting stack traces of all other goroutines
// buffer after the trace for the current goroutine, or not. // into buffer after the trace for the current goroutine.
// Required. // Optional with default value as false.
StackAll bool DisableStackAll bool
// PrintStack is a flag to print stack or not. // DisablePrintStack disables printing stack trace.
// Required. // Optional with default value as false.
PrintStack bool DisablePrintStack bool
} }
) )
var ( var (
// DefaultRecoverConfig is the default recover middleware config. // DefaultRecoverConfig is the default recover middleware config.
DefaultRecoverConfig = RecoverConfig{ DefaultRecoverConfig = RecoverConfig{
StackSize: 4 << 10, // 4 KB StackSize: 4 << 10, // 4 KB
StackAll: true, DisableStackAll: false,
PrintStack: true, DisablePrintStack: false,
} }
) )
@ -61,8 +61,9 @@ func RecoverFromConfig(config RecoverConfig) echo.MiddlewareFunc {
err = fmt.Errorf("%v", r) err = fmt.Errorf("%v", r)
} }
stack := make([]byte, config.StackSize) stack := make([]byte, config.StackSize)
length := runtime.Stack(stack, config.StackAll) length := runtime.Stack(stack, !config.DisableStackAll)
if config.PrintStack { println(config.DisablePrintStack)
if !config.DisablePrintStack {
c.Logger().Printf("[%s] %s %s", color.Red("PANIC RECOVER"), err, stack[:length]) c.Logger().Printf("[%s] %s %s", color.Red("PANIC RECOVER"), err, stack[:length])
} }
c.Error(err) c.Error(err)

View File

@ -12,16 +12,16 @@ 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 is the directory from where the static content is served.
// Optional with default value as `DefaultStaticConfig.Root`. // Optional with default value as "".
Root string `json:"root"` Root string `json:"root"`
// Index is the list of index files to be searched and used when serving // Index is the list of index files to be searched and used when serving
// a directory. // a directory.
// Optional with default value as `DefaultStaticConfig.Index`. // 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. // Browse is a flag to enable/disable directory browsing.
// Required. // Optional with default value as false.
Browse bool `json:"browse"` Browse bool `json:"browse"`
} }
) )