middleware

package
v0.0.0-...-2c9f6af Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

CORS returns a gin middleware that enforces CORS based on the cors.allowed_origins SystemConfig value, read from the database on every request so admin edits take effect immediately (no restart). If the key is missing or the DB errors, it falls back to ["*"] (allow all, no credentials), matching config.DefaultConfig().

func Logger

func Logger() gin.HandlerFunc

Logger logs each request via logrus (method, path, status, latency, client). When the request carries an authenticated node (set by NodeAuth on the /api/v1/server group), the node's id is included as node_id.

func NodeAuth

func NodeAuth(db *gorm.DB) gin.HandlerFunc

NodeAuth authenticates a vgate server (node) via the node_id (public) and token (secret) query params. The node is looked up by node_id, then the token is compared in constant time. On success the *model.Node is stored in the gin context under the "node" key.

func RateLimit

func RateLimit(rps, burst int) gin.HandlerFunc

RateLimit returns a per-client-IP token-bucket limiter allowing `rps` requests/second with burst `burst`. Exceeding the bucket returns 429.

The per-IP limiter map is bounded: when it exceeds maxEntries, the whole map is reset (crude but prevents unbounded growth under IP-spoofing attack). For high-scale deployments, replace with a TTL-based cache.

func RequireAdmin

func RequireAdmin(svc *service.AuthService) gin.HandlerFunc

RequireAdmin verifies an admin JWT and stores admin_id/role/username in context.

func RequireSuperAdmin

func RequireSuperAdmin(svc *service.AuthService) gin.HandlerFunc

RequireSuperAdmin verifies an admin JWT with role "super_admin".

func RequireUser

func RequireUser(svc *service.AuthService) gin.HandlerFunc

RequireUser verifies a user JWT and stores user_id in context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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