api

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(secretProvider JWTSecretProvider, blocklist BlocklistChecker) gin.HandlerFunc

AuthMiddleware validates JWT tokens on protected routes.

func CORSMiddleware

func CORSMiddleware(allowedOrigins []string) gin.HandlerFunc

CORSMiddleware configures CORS for the Vue frontend.

func RateLimitMiddleware added in v0.0.4

func RateLimitMiddleware(limiter *IPRateLimiter) gin.HandlerFunc

RateLimitMiddleware creates a Gin middleware that limits requests per IP.

func SetupRouter

func SetupRouter(cfg RouterConfig) *gin.Engine

SetupRouter creates and configures the Gin router.

Types

type BlocklistChecker

type BlocklistChecker interface {
	IsBlocked(ctx context.Context, jti string) (bool, error)
}

BlocklistChecker checks if a JWT token ID is revoked.

type CachedJWTSecretProvider added in v0.0.4

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

CachedJWTSecretProvider wraps a JWTSecretProvider with in-memory caching. The secret is refreshed from the underlying source every refreshInterval.

func NewCachedJWTSecretProvider added in v0.0.4

func NewCachedJWTSecretProvider(source JWTSecretProvider, refreshInterval time.Duration) *CachedJWTSecretProvider

NewCachedJWTSecretProvider creates a new cached JWT secret provider.

func (*CachedJWTSecretProvider) GetJWTSecret added in v0.0.4

func (p *CachedJWTSecretProvider) GetJWTSecret(ctx context.Context) (string, error)

GetJWTSecret returns the cached secret, refreshing from the source if stale.

type IPRateLimiter added in v0.0.4

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

IPRateLimiter provides per-IP rate limiting with periodic cleanup.

func NewIPRateLimiter added in v0.0.4

func NewIPRateLimiter(r rate.Limit, burst int) *IPRateLimiter

NewIPRateLimiter creates a new per-IP rate limiter. r is the token refill rate (tokens per second), burst is the bucket size.

func (*IPRateLimiter) GetLimiter added in v0.0.4

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

GetLimiter returns the rate limiter for the given IP.

type JWTSecretProvider added in v0.0.4

type JWTSecretProvider interface {
	GetJWTSecret(ctx context.Context) (string, error)
}

JWTSecretProvider loads the current JWT secret from the database.

type RouterConfig

type RouterConfig struct {
	Debug     bool
	JWTSecret JWTSecretProvider
	Settings  *store.SettingsStore
	Secrets   *store.SecretStore
	Upstreams *store.UpstreamStore
	Instances *store.InstanceStore
	Slaves    *store.SlaveStore
	Traffic   *store.TrafficStore
	Blocklist *store.TokenBlocklistStore
	Backups   *store.BackupStore
	Docker    *dockerutil.DockerClient
	// Services
	SecretSvc       *service.SecretService
	UpstreamSvc     *service.UpstreamService
	ContainerSvc    *service.ContainerService
	DockerSvc       *service.DockerService
	GeoblockSvc     *service.GeoblockService
	BotDeps         *bot.Dependencies
	HealthSvc       *service.HealthService
	TrafficSvc      *service.TrafficService
	ReplSvc         *service.ReplicationService
	UpdateSvc       *service.UpdateService
	TelemtUpdateSvc *service.TelemtUpdateService
	TelemtCfg       *service.DBTelemtConfig
	CORSOrigins     []string // defaults to ["*"] if empty
}

RouterConfig holds dependencies for router setup.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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