http

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApiMiddleware

func NewApiMiddleware(f LimitFunc, resource string) gin.HandlerFunc

NewApiMiddleware creates middleware to limit request rate for REST API.

func NewHttpMiddleware

func NewHttpMiddleware(f LimitFunc, resource string) middlewares.Middleware

NewHttpMiddleware creates middleware to limit HTTP request rate.

Types

type LimitFunc

type LimitFunc func(ctx context.Context, resource string) error

type LimiterFactory

type LimiterFactory interface {
	// GetGroupAndKey generates group and key from context
	GetGroupAndKey(ctx context.Context, resource string) (group, key string, err error)
	// Create creates limiter by resource and group
	Create(ctx context.Context, resource, group string) (rate.Limiter, error)
}

type Registry

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

func NewRegistry

func NewRegistry(factory LimiterFactory) *Registry

func (*Registry) GC

func (r *Registry) GC()

func (*Registry) Limit

func (r *Registry) Limit(ctx context.Context, resource string) error

Limit limits request rate according to HTTP request context. Note, it requires to hook IP/API key middlewares for HTTP server.

func (*Registry) LimitN added in v0.2.1

func (r *Registry) LimitN(ctx context.Context, resource string, n int) error

Limit limits request rate according to HTTP request context. Note, it requires to hook IP/API key middlewares for HTTP server.

func (*Registry) Remove

func (r *Registry) Remove(resource, group string)

func (*Registry) RemoveAll

func (r *Registry) RemoveAll()

func (*Registry) RemoveBatch

func (r *Registry) RemoveBatch(items map[string]map[string]bool)

func (*Registry) ScheduleGC

func (r *Registry) ScheduleGC(interval time.Duration)

Jump to

Keyboard shortcuts

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