api

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleAdmin  = "admin"
	RoleClient = "client"
	RoleGuest  = "guest"
)

Variables

This section is empty.

Functions

func CheckWebSocketOrigin

func CheckWebSocketOrigin(r *http.Request) bool

func EnableWebSocketCompression

func EnableWebSocketCompression(upgrader *websocket.Upgrader)

func GetClients

func GetClients(c *gin.Context)

func GetPrincipal

func GetPrincipal(c *gin.Context) *rpc.Principal

GetPrincipal 读取已识别的主体;若中间件未运行则返回 nil。

func GetRole

func GetRole(c *gin.Context) string

GetRole 获取当前请求的角色

func IdentifyPrincipal

func IdentifyPrincipal(c *gin.Context) *rpc.Principal

IdentifyPrincipal 识别当前请求的调用主体。不写入任何状态,可安全多次调用。 识别优先级与历史 IdentityMiddleware 一致:API Key > Session > Client Token > 匿名。

func IdentityMiddleware

func IdentityMiddleware() gin.HandlerFunc

IdentityMiddleware 统一身份识别中间件,在路由栈最外层运行。 负责识别当前请求者身份(Admin / Client / Guest),并写入 Context。 身份识别统一委托给 IdentifyPrincipal;同时保留旧的 c.Set 键(role/uuid/ api_key/session/client_uuid)以兼容现有 handler 与中间件。

func IsWebSocketUpgrade

func IsWebSocketUpgrade(c *gin.Context) bool

func PrivateSiteMiddleware

func PrivateSiteMiddleware() gin.HandlerFunc

PrivateSiteMiddleware 私有站点访问控制。 依赖 IdentityMiddleware 已设置的 role,对未认证的访客在私有站点模式下进行拦截。

func RequireRole

func RequireRole(allowedRoles ...string) gin.HandlerFunc

RequireRole 声明式权限校验中间件,仅允许指定角色通过。

func RequireSensitive2FA

func RequireSensitive2FA() gin.HandlerFunc

func Respond

func Respond(c *gin.Context, httpStatus int, status string, message string, data interface{})

Respond sends a standardized JSON response.

func RespondError

func RespondError(c *gin.Context, httpStatus int, message string)

RespondError sends an error response with message.

func RespondSuccess

func RespondSuccess(c *gin.Context, data interface{})

RespondSuccess sends a success response with data.

func RespondSuccessMessage

func RespondSuccessMessage(c *gin.Context, message string, data interface{})

RespondSuccessMessage sends a success response with message and data.

func SetPrincipal

func SetPrincipal(c *gin.Context, p *rpc.Principal)

SetPrincipal 将已识别的主体写入 gin.Context,供下游(RPC 边界等)复用。

func UpgradeSafeConn

func UpgradeSafeConn(c *gin.Context, options ...WebSocketUpgradeOption) (*connection.SafeConn, error)

UpgradeSafeConn upgrades the request to a WebSocket and attaches the process-wide plugin frame interceptor (when one is wired). A plugin wsConnect hook may deny the connection: the peer receives a policy-violation close frame and the caller gets an error.

func UpgradeWebSocket

func UpgradeWebSocket(c *gin.Context, options ...WebSocketUpgradeOption) (*websocket.Conn, error)

func VerifySensitive2FA

func VerifySensitive2FA(c *gin.Context) error

VerifySensitive2FA gin 适配层:从 gin.Context 提取参数后委托核心校验。

func VerifySensitive2FACore

func VerifySensitive2FACore(userUUID, code string, isAPIKey bool) error

VerifySensitive2FACore 传输无关的 2FA 校验核心。 输入原始值:userUUID、2FA code、是否为 API Key。 API Key 豁免;未启用 2FA 的用户放行;其余需要有效 code。

Types

type Response

type Response struct {
	Status  string      `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type WebSocketUpgradeOption

type WebSocketUpgradeOption func(*websocket.Upgrader)

Directories

Path Synopsis
Package ipinfo 实现第三方主题(LuminaPlus)所需的「IP 信息」HTTP 接口。
Package ipinfo 实现第三方主题(LuminaPlus)所需的「IP 信息」HTTP 接口。

Jump to

Keyboard shortcuts

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