Documentation ¶
Index ¶
- Variables
- func ActivityType(fl validator.FieldLevel) bool
- func AuthRequired() echo.MiddlewareFunc
- func ErrHandler(e *echo.Echo) func(err error, c echo.Context)
- func IPRateLimit(store limiter.Store, rate limiter.Rate) echo.MiddlewareFunc
- func Logger(logger *zap.Logger) echo.MiddlewareFunc
- func NewStore(rdb *redis.Client, prefix string, keyPairs []byte) *store
- func NewTraceCtx(c echo.Context) context.Context
- func OK(c echo.Context, data interface{}) error
- func Recover() echo.MiddlewareFunc
- func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc
- func SetRequestID() echo.MiddlewareFunc
- func StatsField(fl validator.FieldLevel) bool
- func StatsFreq(fl validator.FieldLevel) bool
- func StatsMethod(fl validator.FieldLevel) bool
- type CustomValidator
- type Error
- type GobSerializer
- type JSONSerializer
- type RecoverConfig
- type RedisStore
- func (s *RedisStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *RedisStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *RedisStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *RedisStore) SetKeyPrefix(p string)
- func (s *RedisStore) SetMaxAge(v int)
- func (s *RedisStore) SetMaxLength(l int)
- func (s *RedisStore) SetSerializer(ss SessionSerializer)
- type SessionSerializer
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = NewError(http.StatusBadRequest, 40000, "bad request") ErrAuth = NewError(http.StatusUnauthorized, 40001, "unauthorized") ErrForbidden = NewError(http.StatusForbidden, 40002, "forbidden") ErrReachLimit = NewError(http.StatusTooManyRequests, 40003, "too many requests") ErrParam = NewError(http.StatusBadRequest, 40005, "invalid parameters") ErrNotFound = NewError(http.StatusNotFound, 40006, "resource not found") ErrConflict = NewError(http.StatusConflict, 40007, "resource exists") ErrInternal = NewError(http.StatusInternalServerError, 50000, "internal server error") ErrDB = NewError(http.StatusInternalServerError, 50001, "db error") ErrRedis = NewError(http.StatusInternalServerError, 50002, "redis error") ErrThirdAPI = NewError(http.StatusServiceUnavailable, 60000, "third api error") )
global err
var ( // DefaultRecoverConfig is the default Recover middleware config. DefaultRecoverConfig = RecoverConfig{ StackSize: 4 << 10, DisableStackAll: false, DisablePrintStack: false, } )
Functions ¶
func ActivityType ¶
func ActivityType(fl validator.FieldLevel) bool
ActivityType validate activity type
func IPRateLimit ¶
func IPRateLimit(store limiter.Store, rate limiter.Rate) echo.MiddlewareFunc
IPRateLimit by ip
func NewTraceCtx ¶
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()`.
Types ¶
type CustomValidator ¶
func NewValidator ¶
func NewValidator() *CustomValidator
func (*CustomValidator) Validate ¶
func (cv *CustomValidator) Validate(i interface{}) error
type Error ¶
type Error struct { Status int `json:"-"` // Status http 状态码 Code int `json:"code"` // Code 错误状态码 Message string `json:"message"` // Message 错误信息 ErrorMessage string `json:"error,omitempty"` // ErrorMessage 只有在非 gin.ReleaseMode 模式下才会在接口中展示,但会在日志中展示 }
Error 封装接口错误信息
type GobSerializer ¶
type GobSerializer struct{}
GobSerializer gob 序列化、反序列化
func (GobSerializer) Deserialize ¶
func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error
Deserialize 反序列化
type JSONSerializer ¶
type JSONSerializer struct{}
JSONSerializer json 序列化、反序列化
func (JSONSerializer) Deserialize ¶
func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error
Deserialize 反序列化
type RecoverConfig ¶
type RecoverConfig struct { // 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"` }
RecoverConfig defines the config for Recover middleware.
type RedisStore ¶
type RedisStore struct { Codecs []securecookie.Codec Options *sessions.Options // default configuration // contains filtered or unexported fields }
RedisStore session redis 存储
func NewRedisStore ¶
func NewRedisStore(rdb *redis.Client, prefix string, keyPairs []byte) *RedisStore
NewRedisStore instantiates a RedisStore
func (*RedisStore) Get ¶
Get returns a session for the given name after adding it to the registry.
See gorilla/sessions FilesystemStore.Get().
func (*RedisStore) New ¶
New returns a session for the given name without adding it to the registry.
See gorilla/sessions FilesystemStore.New().
func (*RedisStore) Save ¶
func (s *RedisStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
Save adds a single session to the response.
func (*RedisStore) SetKeyPrefix ¶
func (s *RedisStore) SetKeyPrefix(p string)
SetKeyPrefix set the prefix
func (*RedisStore) SetMaxAge ¶
func (s *RedisStore) SetMaxAge(v int)
SetMaxAge restricts the maximum age, in seconds, of the session record both in database and a browser. This is to change session storage configuration. If you want just to remove session use your session `s` object and change it's `Options.MaxAge` to -1, as specified in
http://godoc.org/github.com/gorilla/sessions#Options
Default is the one provided by this package value - `sessionExpire`. Set it to 0 for no restriction. Because we use `MaxAge` also in SecureCookie crypting algorithm you should use this function to change `MaxAge` value.
func (*RedisStore) SetMaxLength ¶
func (s *RedisStore) SetMaxLength(l int)
SetMaxLength sets RedisStore.maxLen if the `l` argument is greater or equal 0 maxLen restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new RedisStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096,
func (*RedisStore) SetSerializer ¶
func (s *RedisStore) SetSerializer(ss SessionSerializer)
SetSerializer sets the serializer