Documentation
¶
Index ¶
- Constants
- func AccessLogMiddleware() func(http.Handler) http.Handler
- func AuthMiddleware(api *API, auth *authsvc.Service) func(http.Handler) http.Handler
- func BoolValue(value any) (bool, bool)
- func ClientIP(request *http.Request) string
- func DecodeJSONBody(body io.Reader, target any, allowEmpty bool) error
- func DesktopSessionTokenMiddleware(api *API, token string, apiPrefix string) func(http.Handler) http.Handler
- func GatewayClientErrorDetail(status int, detail string) string
- func Int64Value(value any) int64
- func IsClientMessageError(err error) bool
- func IsClientMessageText(message string) bool
- func IsStructuredSessionKeyError(err error) bool
- func PublicAuthRoute(request *http.Request) bool
- func RecoverMiddleware(api *API) func(http.Handler) http.Handler
- func RequestContextMiddleware(baseLogger *slog.Logger) func(http.Handler) http.Handler
- func StringValue(value any) string
- type API
- func (a *API) BaseLogger() *slog.Logger
- func (a *API) BindJSON(writer http.ResponseWriter, request *http.Request, target any) bool
- func (a *API) BindJSONAllowEmpty(writer http.ResponseWriter, request *http.Request, target any) bool
- func (a *API) HandleNotImplemented(group string) http.HandlerFunc
- func (a *API) WriteFailure(writer http.ResponseWriter, status int, detail string)
- func (a *API) WriteJSON(writer http.ResponseWriter, status int, payload map[string]any)
- func (a *API) WriteSuccess(writer http.ResponseWriter, data any)
- type WebSocketSender
Constants ¶
const ( // DesktopSessionTokenHeader 是桌面 shell 注入到 HTTP API 请求里的本地会话凭据。 DesktopSessionTokenHeader = "X-Nexus-Desktop-Token" // DesktopSessionTokenCookie 是 WKWebView WebSocket 握手使用的本地会话凭据。 DesktopSessionTokenCookie = "nexus_desktop_token" // DesktopWebSocketSubprotocol 是桌面 WebSocket 握手协商出的非敏感子协议。 DesktopWebSocketSubprotocol = "nexus.desktop.v1" // DesktopSessionTokenProtocolPrefix 是 WebSocket 握手使用的子协议 token 前缀。 DesktopSessionTokenProtocolPrefix = "nexus.desktop.token." )
const WebSocketWriteTimeout = 10 * time.Second
WebSocketWriteTimeout 是写出 WebSocket 事件的超时窗口。
Variables ¶
This section is empty.
Functions ¶
func AccessLogMiddleware ¶
AccessLogMiddleware 记录请求访问日志。
func AuthMiddleware ¶
AuthMiddleware 把认证状态写入请求上下文。
func DecodeJSONBody ¶
DecodeJSONBody 解析并校验单个 JSON 顶层值。
func DesktopSessionTokenMiddleware ¶ added in v0.1.3
func DesktopSessionTokenMiddleware(api *API, token string, apiPrefix string) func(http.Handler) http.Handler
DesktopSessionTokenMiddleware 校验桌面 App 本地 API 面的一次性会话 token。
func GatewayClientErrorDetail ¶
GatewayClientErrorDetail 规范化客户端可见错误文案。
func IsClientMessageError ¶
IsClientMessageError 判断错误是否适合直接返回给客户端。
func IsClientMessageText ¶
IsClientMessageText 判断文本是否属于客户端可理解错误。
func IsStructuredSessionKeyError ¶
IsStructuredSessionKeyError 判断错误是否为结构化 session key 错误。
func PublicAuthRoute ¶
PublicAuthRoute 判断是否为无需认证的公开路由。
func RecoverMiddleware ¶
RecoverMiddleware 捕获 panic 并返回标准错误。
func RequestContextMiddleware ¶
RequestContextMiddleware 注入 request_id 和 request logger。
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API 提供处理器共享的 HTTP 响应与上下文辅助能力。
func (*API) BindJSONAllowEmpty ¶
func (a *API) BindJSONAllowEmpty(writer http.ResponseWriter, request *http.Request, target any) bool
BindJSONAllowEmpty 解析可为空的 JSON 请求体。
func (*API) HandleNotImplemented ¶
func (a *API) HandleNotImplemented(group string) http.HandlerFunc
HandleNotImplemented 返回占位路由 handler。
func (*API) WriteFailure ¶
func (a *API) WriteFailure(writer http.ResponseWriter, status int, detail string)
WriteFailure 写入失败响应。
func (*API) WriteSuccess ¶
func (a *API) WriteSuccess(writer http.ResponseWriter, data any)
WriteSuccess 写入成功响应。
type WebSocketSender ¶
type WebSocketSender struct {
// contains filtered or unexported fields
}
WebSocketSender 封装单个 WebSocket 连接的并发安全发送能力。
func NewWebSocketSender ¶
func NewWebSocketSender(conn *websocket.Conn) *WebSocketSender
NewWebSocketSender 创建发送器。
func (*WebSocketSender) SendEvent ¶
func (s *WebSocketSender) SendEvent(ctx context.Context, event protocol.EventMessage) error
SendEvent 发送协议事件。