http

package
v0.0.0-...-f6bc33c Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedOrigin

func AllowedOrigin(allowedOrigins []string) func(origin string) bool

func CORSOptions

func CORSOptions(config CORSConfig) cors.Options

func RemoteAddr

func RemoteAddr(r *http.Request) (string, error)

RemoteAddr collects possible remote addresses from a request.

Types

type CORSConfig

type CORSConfig struct {
	AllowedOrigins []string `long:"allowed-origins" description:"Allowed origins for CORS"`
	MaxAge         int      `long:"max-age" description:"Max age (in seconds) for preflight cache"`
}

CORSConfig represents the configuration for CORS.

type RateLimit

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

func NewRateLimit

func NewRateLimit(ctx context.Context, cfg RateLimitConfig) (*RateLimit, error)

func (*RateLimit) NewRequest

func (r *RateLimit) NewRequest(identifier, ip string) error

NewRequest returns nil if the rate has not been exceeded.

type RateLimitConfig

type RateLimitConfig struct {
	CoolDown encoding.Duration `long:"coolDown" description:"rate-limit duration, e.g. 10s, 1m30s, 24h0m0s"`

	AllowList []string `long:"allowList" description:"a list of ip/subnets, e.g. 10.0.0.0/8, 192.168.0.0/16"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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