Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server interface {
// ListenAndServe 用于替代 `http.Server.ListenAndServe`
ListenAndServe(addr string) error
// ListenAndServeTLS 用于替代 `http.Server.ListenAndServeTLS`
ListenAndServeTLS(addr, certFile, keyFile string) error
// Close 直接关闭服务器
Close()
// Shutdown 优雅关闭服务器
// 关闭监听
// 执行之前注册的关闭函数(RegisterShutdownHandler),可以用于清理资源等
// 关闭空闲连接,等待激活的连接变为空闲,再关闭它
Shutdown()
// Restart 重启服务
Restart()
// SetShutdownTimeout 设置优雅退出超时时间
// 服务器会每隔500毫秒检查一次连接是否都断开处理完毕
// 如果超过超时时间,就不再检查,直接退出
// 如果要单独给指定的服务器设置 超时时间,可以使用 WithTimeout
//
// ms: 单位:毫秒,当 <= 0 时无效,直接退出
SetShutdownTimeout(ms int)
// RegisterShutdownHandler 注册关闭函数
// 按照注册的顺序调用这些函数
// 所有已经添加的服务器都会响应这个函数
RegisterShutdownHandler(f func())
// ListenSignal 监听信号
ListenSignal()
}
Server 用来替代 http.Server
Click to show internal directories.
Click to hide internal directories.