1
0
mirror of https://github.com/labstack/echo.git synced 2025-07-17 01:43:02 +02:00

Option to options

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-02-18 07:00:51 -08:00
parent 88f307bedd
commit c0873843ad
5 changed files with 15 additions and 15 deletions

View File

@ -10,18 +10,18 @@ import (
) )
type ( type (
StaticOption struct { StaticOptions struct {
Root string `json:"root"` Root string `json:"root"`
Index string `json:"index"` Index string `json:"index"`
Browse bool `json:"browse"` Browse bool `json:"browse"`
} }
) )
func Static(root string, option ...*StaticOption) echo.HandlerFunc { func Static(root string, options ...*StaticOptions) echo.HandlerFunc {
// Default options // Default options
opt := &StaticOption{Index: "index.html"} opts := &StaticOptions{Index: "index.html"}
if len(option) > 0 { if len(options) > 0 {
opt = option[0] opts = options[0]
} }
return func(c echo.Context) error { return func(c echo.Context) error {
@ -46,10 +46,10 @@ func Static(root string, option ...*StaticOption) echo.HandlerFunc {
d := f d := f
// Index file // Index file
file = path.Join(file, opt.Index) file = path.Join(file, opts.Index)
f, err = fs.Open(file) f, err = fs.Open(file)
if err != nil { if err != nil {
if opt.Browse { if opts.Browse {
dirs, err := d.Readdir(-1) dirs, err := d.Readdir(-1)
if err != nil { if err != nil {
return err return err

View File

@ -8,7 +8,7 @@ import (
) )
type ( type (
BasicAuthOption struct { BasicAuthOptions struct {
} }
BasicAuthFunc func(string, string) bool BasicAuthFunc func(string, string) bool
@ -22,7 +22,7 @@ const (
// //
// For valid credentials it calls the next handler. // For valid credentials it calls the next handler.
// For invalid credentials, it sends "401 - Unauthorized" response. // For invalid credentials, it sends "401 - Unauthorized" response.
func BasicAuth(fn BasicAuthFunc, option ...*BasicAuthOption) echo.MiddlewareFunc { func BasicAuth(fn BasicAuthFunc, options ...*BasicAuthOptions) echo.MiddlewareFunc {
return func(h echo.Handler) echo.Handler { return func(h echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error { return echo.HandlerFunc(func(c echo.Context) error {
// Skip WebSocket // Skip WebSocket

View File

@ -15,7 +15,7 @@ import (
) )
type ( type (
GzipOption struct { GzipOptions struct {
level int level int
} }
@ -27,7 +27,7 @@ type (
// Gzip returns a middleware which compresses HTTP response using gzip compression // Gzip returns a middleware which compresses HTTP response using gzip compression
// scheme. // scheme.
func Gzip(option ...*GzipOption) echo.MiddlewareFunc { func Gzip(options ...*GzipOptions) echo.MiddlewareFunc {
return func(h echo.Handler) echo.Handler { return func(h echo.Handler) echo.Handler {
scheme := "gzip" scheme := "gzip"
return echo.HandlerFunc(func(c echo.Context) error { return echo.HandlerFunc(func(c echo.Context) error {

View File

@ -9,11 +9,11 @@ import (
) )
type ( type (
LogOption struct { LogOptions struct {
} }
) )
func Log(option ...*LogOption) echo.MiddlewareFunc { func Log(options ...*LogOptions) echo.MiddlewareFunc {
return func(h echo.Handler) echo.Handler { return func(h echo.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error { return echo.HandlerFunc(func(c echo.Context) error {
req := c.Request() req := c.Request()

View File

@ -9,13 +9,13 @@ import (
) )
type ( type (
RecoverOption struct { RecoverOptions struct {
} }
) )
// Recover returns a middleware which recovers from panics anywhere in the chain // Recover returns a middleware which recovers from panics anywhere in the chain
// and handles the control to the centralized HTTPErrorHandler. // and handles the control to the centralized HTTPErrorHandler.
func Recover(option ...*RecoverOption) echo.MiddlewareFunc { func Recover(options ...*RecoverOptions) echo.MiddlewareFunc {
return func(h echo.Handler) echo.Handler { return func(h echo.Handler) echo.Handler {
// TODO: Provide better stack trace `https://github.com/go-errors/errors` `https://github.com/docker/libcontainer/tree/master/stacktrace` // TODO: Provide better stack trace `https://github.com/go-errors/errors` `https://github.com/docker/libcontainer/tree/master/stacktrace`
return echo.HandlerFunc(func(c echo.Context) error { return echo.HandlerFunc(func(c echo.Context) error {