Documentation
¶
Overview ¶
Package web provides a simple HTTP multiplexer with middleware support.
Index ¶
- func Address[T utils.UintT | utils.IntT](ip net.IP, port T) string
- func Blob[T ~[]byte | ~string](body T, contentType string, status int) http.HandlerFunc
- func FBlob[T ~[]byte | ~string](body func() (T, error), contentType string) http.HandlerFunc
- func FJSON[T any](body func() (T, error)) http.HandlerFunc
- func JSON(body any, status int) http.HandlerFunc
- func Recoverer(next http.Handler) http.Handler
- func Redirect(to string, permanent ...bool) http.HandlerFunc
- type Middleware
- type Mux
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Middleware ¶
Middleware 定义中间件处理器函数类型,接收下一个处理器并返回包装后的处理器
func BasicAuth ¶
func BasicAuth(username, password string) Middleware
BasicAuth 创建基础认证中间件
- username: 用户名
- password: 密码
返回认证处理器
type Mux ¶
Mux 表示一个HTTP请求多路复用器,支持中间件处理链
func (*Mux) OnShutDown ¶
func (mux *Mux) OnShutDown(fn func())
OnShutDown 设置服务器关闭时的回调函数
- fn: 服务器关闭时执行的函数
Click to show internal directories.
Click to hide internal directories.