mdw

package
v0.0.0-...-58fd0e2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiLimitMiddleware

func ApiLimitMiddleware(opts []ApiLimitOpt) gin.HandlerFunc

func ExtractUserInfoMiddleware

func ExtractUserInfoMiddleware(logger *zap.SugaredLogger, jc *jwt.Client, data *data.Data) gin.HandlerFunc

ExtractUserInfoMiddleware just extract the user info from the request, and save it to the context.

func IPLimitMiddleware

func IPLimitMiddleware(countPerSeconds int, limited func(c *gin.Context, ip string)) gin.HandlerFunc

func LoggerMiddleware

func LoggerMiddleware(apply func(fields *RouterLogFields)) gin.HandlerFunc

func MustLoginMiddleware

func MustLoginMiddleware() gin.HandlerFunc

func MustWithRoleMiddleware

func MustWithRoleMiddleware(needRole string) gin.HandlerFunc

Types

type ApiLimitOpt

type ApiLimitOpt struct {
	Path            string `json:"path"`
	CountPerSeconds int    `json:"count_per_seconds"`
	Slack           int    `json:"slack"`
}

type IPRateLimiter

type IPRateLimiter struct {
	// contains filtered or unexported fields
}

func NewIPRateLimiter

func NewIPRateLimiter(countPerSeconds int) *IPRateLimiter

NewIPRateLimiter . func SetupIPRateLimiter(r rate.Limit, b int) (error) {

func (*IPRateLimiter) AddIP

func (i *IPRateLimiter) AddIP(ip string) *rate.Limiter

AddIP creates a new rate limiter and adds it to the ips map, using the IP address as the key

func (*IPRateLimiter) GetLimiter

func (i *IPRateLimiter) GetLimiter(ip string) *rate.Limiter

GetLimiter returns the rate limiter for the provided IP address if it exists. Otherwise calls AddIP to add IP address to the map

type RouterLogFields

type RouterLogFields struct {
	Status int           `json:"status"`
	Time   time.Duration `json:"time"`
	Method string        `json:"method"`
	Path   string        `json:"path"`
	IP     string        `json:"ip"`
	Agent  string        `json:"agent"`
	Uri    string        `json:"uri"`
}

Jump to

Keyboard shortcuts

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