Documentation
¶
Index ¶
- Constants
- func ApplyCORSHeaders(header http.Header, r *http.Request, corsConfig *conf.Server_CORS)
- func CORSFilter(corsConfig *conf.Server_CORS) khttp.FilterFunc
- func DeviceMiddleware(deviceConfig *conf.Device, logger log.Logger) func(http.Handler) http.Handler
- func GetClientIP(ctx context.Context) string
- func GetGatewayMode(ctx context.Context) bool
- func GetQueryParams(ctx context.Context) map[string]string
- func GetRequestHost(ctx context.Context) string
- func GetRequestURI(ctx context.Context) string
- func GetSessionID(ctx context.Context) string
- func GetSubscribeConfigByToken(ctx context.Context, uc *subscriptionbiz.SubscriptionUseCase, ...) ([]byte, string, error)
- func GetUserAgent(ctx context.Context) string
- func GetUserID(ctx context.Context) int64
- func IsCORSPreflightRequest(r *http.Request) bool
- func JWTAuth(authConfig *conf.Server_Auth) middleware.Middleware
- func LegacyPathCompatFilter() khttp.FilterFunc
- func LegacyRouteGuardFilter() khttp.FilterFunc
- func Logging(logger log.Logger) middleware.Middleware
- func LoggingWithBody(logger log.Logger) middleware.Middleware
- func NotifyMiddleware(...) func(http.Handler) http.Handler
- func PanDomainMiddleware(subscribeConfig *conf.Subscribe, uc *subscriptionbiz.SubscriptionUseCase, ...) func(http.Handler) http.Handler
- func ServerMiddleware(nodeSecret string, logger log.Logger) func(http.Handler) http.Handler
- func SubscribePathCompatFilter(appConf *conf.Application) khttp.FilterFunc
- func TraceMiddleware(logger log.Logger) func(http.Handler) http.Handler
- func WithClientIP(ctx context.Context, clientIP string) context.Context
- func WithGatewayMode(ctx context.Context, gatewayMode bool) context.Context
- func WithQueryParams(ctx context.Context, queryParams map[string]string) context.Context
- func WithRequestHost(ctx context.Context, requestHost string) context.Context
- func WithRequestURI(ctx context.Context, requestURI string) context.Context
- func WithSessionID(ctx context.Context, sessionID string) context.Context
- func WithUserAgent(ctx context.Context, userAgent string) context.Context
- func WithUserID(ctx context.Context, userID int64) context.Context
- type PaymentConfig
- type PaymentParams
- type ResponseWriter
- func (rw *ResponseWriter) CloseNotify() <-chan bool
- func (rw *ResponseWriter) Decrypt() bool
- func (rw *ResponseWriter) Encrypt()
- func (rw *ResponseWriter) Flush()
- func (rw *ResponseWriter) FlushAbort()
- func (rw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (rw *ResponseWriter) Pusher() (pusher http.Pusher)
- func (rw *ResponseWriter) Size() int
- func (rw *ResponseWriter) Status() int
- func (rw *ResponseWriter) Unwrap() http.ResponseWriter
- func (rw *ResponseWriter) Write(data []byte) (n int, err error)
- func (rw *ResponseWriter) WriteHeader(code int)
- func (rw *ResponseWriter) WriteHeaderNow()
- func (rw *ResponseWriter) WriteString(s string) (n int, err error)
- func (rw *ResponseWriter) Written() bool
Constants ¶
const (
// DefaultJWTSecret is the default JWT secret key
DefaultJWTSecret = "your-secret-key-change-in-production"
)
const (
// RequestIdKey 请求ID的HTTP头key
RequestIdKey = "X-Request-ID"
)
const (
// SlowRequestThreshold is the threshold for slow request logging (in milliseconds)
SlowRequestThreshold = 3000
)
Variables ¶
This section is empty.
Functions ¶
func ApplyCORSHeaders ¶
ApplyCORSHeaders applies the configured CORS headers onto the response.
func CORSFilter ¶
func CORSFilter(corsConfig *conf.Server_CORS) khttp.FilterFunc
CORSFilter returns a Kratos HTTP filter backed by server.cors config.
func DeviceMiddleware ¶
DeviceMiddleware 设备加密中间件 用于处理设备客户端的请求加密/解密
func GetClientIP ¶
GetClientIP retrieves client IP from context
func GetGatewayMode ¶
GetGatewayMode retrieves gateway mode flag from context
func GetQueryParams ¶
GetQueryParams retrieves the original query params from context.
func GetRequestHost ¶
GetRequestHost retrieves request host from context
func GetRequestURI ¶
GetRequestURI retrieves request URI from context
func GetSessionID ¶
GetSessionID retrieves session ID from context
func GetSubscribeConfigByToken ¶
func GetSubscribeConfigByToken(ctx context.Context, uc *subscriptionbiz.SubscriptionUseCase, token, userAgent string, r *http.Request) ([]byte, string, error)
GetSubscribeConfigByToken 根据token获取订阅配置 这个函数需要调用subscription service来获取配置
func GetUserAgent ¶
GetUserAgent retrieves User-Agent from context
func IsCORSPreflightRequest ¶
IsCORSPreflightRequest reports whether the request is a browser preflight.
func JWTAuth ¶
func JWTAuth(authConfig *conf.Server_Auth) middleware.Middleware
JWTAuth returns a JWT authentication middleware
func LegacyPathCompatFilter ¶
func LegacyPathCompatFilter() khttp.FilterFunc
LegacyPathCompatFilter keeps old Gin-style trailing-slash API paths working.
func LegacyRouteGuardFilter ¶
func LegacyRouteGuardFilter() khttp.FilterFunc
LegacyRouteGuardFilter blocks new-only HTTP routes that do not exist in the old project.
func Logging ¶
func Logging(logger log.Logger) middleware.Middleware
Logging returns a logging middleware for HTTP requests
func LoggingWithBody ¶
func LoggingWithBody(logger log.Logger) middleware.Middleware
LoggingWithBody returns a logging middleware with request/response body logging Note: This middleware logs request and response bodies, use with caution as it may impact performance
func NotifyMiddleware ¶
func NotifyMiddleware(getPaymentConfigFunc func(ctx context.Context, token string) (*PaymentConfig, error), logger log.Logger) func(http.Handler) http.Handler
NotifyMiddleware 支付通知中间件 用于处理支付平台的回调通知
func PanDomainMiddleware ¶
func PanDomainMiddleware(subscribeConfig *conf.Subscribe, uc *subscriptionbiz.SubscriptionUseCase, logger log.Logger) func(http.Handler) http.Handler
PanDomainMiddleware 泛域名订阅中间件 用于处理泛域名的订阅请求,例如: token.example.com
func ServerMiddleware ¶
ServerMiddleware 服务器节点认证中间件 用于验证节点服务器的请求,通过secret_key验证
func SubscribePathCompatFilter ¶
func SubscribePathCompatFilter(appConf *conf.Application) khttp.FilterFunc
SubscribePathCompatFilter enforces the old project's subscribe_path behavior: once a custom path is configured, only that path is allowed externally.
func TraceMiddleware ¶
TraceMiddleware 追踪中间件 使用OpenTelemetry进行分布式追踪
func WithClientIP ¶
WithClientIP stores client IP in context.
func WithGatewayMode ¶
WithGatewayMode stores gateway mode flag in context.
func WithQueryParams ¶
WithQueryParams stores the original query params in context.
func WithRequestHost ¶
WithRequestHost stores request host in context.
func WithRequestURI ¶
WithRequestURI stores request URI in context.
func WithSessionID ¶
WithSessionID stores session ID in context
func WithUserAgent ¶
WithUserAgent stores user agent in context.
Types ¶
type PaymentConfig ¶
PaymentConfig 支付配置
type PaymentParams ¶
PaymentParams 支付参数
type ResponseWriter ¶
type ResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
ResponseWriter 加密响应写入器
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter, r *http.Request, encryptionKey string, logger log.Logger) *ResponseWriter
NewResponseWriter 创建加密响应写入器
func (*ResponseWriter) CloseNotify ¶
func (rw *ResponseWriter) CloseNotify() <-chan bool
CloseNotify 关闭通知
func (*ResponseWriter) Hijack ¶
func (rw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack 劫持连接
func (*ResponseWriter) Write ¶
func (rw *ResponseWriter) Write(data []byte) (n int, err error)
Write 写入数据
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(code int)
WriteHeader 写入状态码
func (*ResponseWriter) WriteHeaderNow ¶
func (rw *ResponseWriter) WriteHeaderNow()
WriteHeaderNow 立即写入状态码
func (*ResponseWriter) WriteString ¶
func (rw *ResponseWriter) WriteString(s string) (n int, err error)
WriteString 写入字符串