middleware

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLoggerConfig is the default Logger middleware config.
	DefaultLoggerConfig = LoggerConfig{
		Skipper: func(context echo.Context) bool {
			if strings.Index(context.Request().URL.Path, "/swagger") != -1 {
				return true
			}
			return false
		},
		// contains filtered or unexported fields
	}
)

Functions

func CircuitBreaker

func CircuitBreaker(config CircuitBreakerConfig) echo.MiddlewareFunc

CircuitBreaker 断路器中间件

func InitValidate

func InitValidate(e *echo.Echo)

func Logger

func Logger() echo.MiddlewareFunc

restapi监控日志

func LoggerWithConfig

func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc

LoggerWithConfig returns a Logger middleware with config. See: `Logger()`.

func NewDefaultStore

func NewDefaultStore() limiter.Store

NewDefaultStore is in-memory store

func Recover

func Recover() echo.MiddlewareFunc

Recover returns a middleware which recovers from panics anywhere in the chain and handles the control to the centralized HTTPErrorHandler.

func RecoverWithConfig

func RecoverWithConfig(config *RecoverConfig) echo.MiddlewareFunc

RecoverWithConfig returns a Recover middleware with config. See: `Recover()`.

func RouteReachedLimitGlobal

func RouteReachedLimitGlobal(limit int64, period time.Duration) echo.MiddlewareFunc

api接口全局限流器

func RouteReachedLimitLocal

func RouteReachedLimitLocal(limit int64, period time.Duration) echo.MiddlewareFunc

api接口本地限流器

func RouteUserLimitGlobal

func RouteUserLimitGlobal(limit int64, period time.Duration) echo.MiddlewareFunc

RouteUserLimitGlobal api接口单用户全局限流器

func SetErrNotifyUrl

func SetErrNotifyUrl(s string)

报错通知地址 不设置不发送

func SetLimitStoreOptionsConfig

func SetLimitStoreOptionsConfig(c LimitStoreOptionsConfig)

Types

type BodyDumpHandler

type BodyDumpHandler func(echo.Context, time.Time, []byte, []byte)

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	Skipper                middleware.Skipper
	Name                   string `json:"name"` // should be unique
	Timeout                int    `json:"timeout"`
	MaxConcurrentRequests  int    `json:"max_concurrent_requests"`
	RequestVolumeThreshold int    `json:"request_volume_threshold"`
	SleepWindow            int    `json:"sleep_window"`
	ErrorPercentThreshold  int    `json:"error_percent_threshold"`
}

CircuitBreakerConfig 断路器配置 Name 需保证唯一

type CustomBinder

type CustomBinder struct{}

CustomBinder 自定bind

func (*CustomBinder) Bind

func (cb *CustomBinder) Bind(i interface{}, e echo.Context) (err error)

Bind 自定义bind

type LimitStoreOptionsConfig

type LimitStoreOptionsConfig struct {
	Prefix string
	Client redis.Client
}

type LoggerConfig

type LoggerConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper echoMiddleware.Skipper

	// Output is a writer where logs in JSON format are written.
	// Optional. Default value os.Stdout.
	Output io.Writer

	Handler BodyDumpHandler
	// contains filtered or unexported fields
}

LoggerConfig defines the config for Logger middleware.

type RecoverConfig

type RecoverConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper echoMiddleware.Skipper

	// Size of the stack to be printed.
	// Optional. Default value 4KB.
	StackSize int `yaml:"stack_size"`

	// DisableStackAll disables formatting stack traces of all other goroutines
	// into buffer after the trace for the current goroutine.
	// Optional. Default value false.
	DisableStackAll bool `yaml:"disable_stack_all"`

	// DisablePrintStack disables printing stack trace.
	// Optional. Default value as false.
	DisablePrintStack bool `yaml:"disable_print_stack"`

	// LogLevel is log level to printing stack trace.
	// Optional. Default value 0 (Print).
	LogLevel log.Lvl
}

RecoverConfig defines the config for Recover middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL