mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
Option to options
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
88f307bedd
commit
c0873843ad
@ -10,18 +10,18 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
StaticOption struct {
|
||||
StaticOptions struct {
|
||||
Root string `json:"root"`
|
||||
Index string `json:"index"`
|
||||
Browse bool `json:"browse"`
|
||||
}
|
||||
)
|
||||
|
||||
func Static(root string, option ...*StaticOption) echo.HandlerFunc {
|
||||
func Static(root string, options ...*StaticOptions) echo.HandlerFunc {
|
||||
// Default options
|
||||
opt := &StaticOption{Index: "index.html"}
|
||||
if len(option) > 0 {
|
||||
opt = option[0]
|
||||
opts := &StaticOptions{Index: "index.html"}
|
||||
if len(options) > 0 {
|
||||
opts = options[0]
|
||||
}
|
||||
|
||||
return func(c echo.Context) error {
|
||||
@ -46,10 +46,10 @@ func Static(root string, option ...*StaticOption) echo.HandlerFunc {
|
||||
d := f
|
||||
|
||||
// Index file
|
||||
file = path.Join(file, opt.Index)
|
||||
file = path.Join(file, opts.Index)
|
||||
f, err = fs.Open(file)
|
||||
if err != nil {
|
||||
if opt.Browse {
|
||||
if opts.Browse {
|
||||
dirs, err := d.Readdir(-1)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
BasicAuthOption struct {
|
||||
BasicAuthOptions struct {
|
||||
}
|
||||
|
||||
BasicAuthFunc func(string, string) bool
|
||||
@ -22,7 +22,7 @@ const (
|
||||
//
|
||||
// For valid credentials it calls the next handler.
|
||||
// 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 echo.HandlerFunc(func(c echo.Context) error {
|
||||
// Skip WebSocket
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
GzipOption struct {
|
||||
GzipOptions struct {
|
||||
level int
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ type (
|
||||
|
||||
// Gzip returns a middleware which compresses HTTP response using gzip compression
|
||||
// scheme.
|
||||
func Gzip(option ...*GzipOption) echo.MiddlewareFunc {
|
||||
func Gzip(options ...*GzipOptions) echo.MiddlewareFunc {
|
||||
return func(h echo.Handler) echo.Handler {
|
||||
scheme := "gzip"
|
||||
return echo.HandlerFunc(func(c echo.Context) error {
|
||||
|
@ -9,11 +9,11 @@ import (
|
||||
)
|
||||
|
||||
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 echo.HandlerFunc(func(c echo.Context) error {
|
||||
req := c.Request()
|
||||
|
@ -9,13 +9,13 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
RecoverOption struct {
|
||||
RecoverOptions struct {
|
||||
}
|
||||
)
|
||||
|
||||
// Recover returns a middleware which recovers from panics anywhere in the chain
|
||||
// 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 {
|
||||
// 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user