Documentation
¶
Index ¶
- func CORS(sysCfg *service.SystemConfigService) gin.HandlerFunc
- func Logger() gin.HandlerFunc
- func NodeAuth(db *gorm.DB) gin.HandlerFunc
- func RateLimit(rps, burst int) gin.HandlerFunc
- func RequireAdmin(svc *service.AuthService) gin.HandlerFunc
- func RequireSuperAdmin(svc *service.AuthService) gin.HandlerFunc
- func RequireUser(svc *service.AuthService) gin.HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
func CORS(sysCfg *service.SystemConfigService) gin.HandlerFunc
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.