Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessLog ¶
type AccessLog struct {
// Logger 必填,打印日志的 logger
Logger xlog.Logger
// OnCookies 可选,处理 Cookie
OnCookies func(cookies []*http.Cookie) []xlog.Attr
// OnHeaders 可选,处理 Header
OnHeaders func(h http.Header) []xlog.Attr
// OnPanic 可选,panic 后,自定义输出
OnPanic func(w http.ResponseWriter, r *http.Request, re any)
// OnRequest 可选,ctx 日志字段初始化完成后,在执行后续 ServeHTTP 方法前调用
OnRequest func(ctx context.Context, r *http.Request)
// RePanic 当 panic 发生后,是否将 panic 重新抛出
RePanic bool
}
AccessLog 打印访问日志
type AntiTheft ¶
type AntiTheft struct {
// AllowDomain 有效的域名,如 example.com,则允许此域名以及所其子域名来源的 refer
AllowDomain []string
xlog.WithLogger
// Forbidden 当判断无效请求时,的回调 handler,可选
Forbidden http.Handler
// contains filtered or unexported fields
}
AntiTheft 使用 refer 信息判断请求来源是否有效
type Cache ¶
type Cache struct {
// Store 必填,缓存对象
Store xcache.Cache[string, string]
// Key 必填,缓存的 key,在 Handler 未执行前执行
// 返回值的第一个参数是缓存的 key,第二个参数是缓存有效期,若为 0 则不缓存
Key func(w http.ResponseWriter, r *http.Request) (string, time.Duration)
// Log 是否添加日志状态字段,可选
// 日志字段名为 xch,可选值:n-无缓存,r-读取并使用缓存,w-写缓存
Log bool
}
Cache 给 GET 请求添加缓存
Click to show internal directories.
Click to hide internal directories.