feat: redesign server startup around Run options

Replace the old RunShutdown and RunTLS style entry points with a single Run(opts...) API for v1. Add focused startup semantics tests, keep TLS and graceful shutdown independent, ensure sibling servers are cleaned up on startup failure, and update docs to match the new option-based startup model.
This commit is contained in:
wjqserver 2026-04-07 17:44:55 +08:00
parent fca9bbd3ef
commit e4d3eed379
13 changed files with 577 additions and 335 deletions

View file

@ -404,11 +404,18 @@ func (engine *Engine) setProtocols(config *ProtocolsConfig) {
}()
}
// applyDefaultServerConfig 应用框架的默认配置到 http.Server
func (engine *Engine) applyDefaultServerConfig(srv *http.Server) {
if engine.serverProtocols != nil {
srv.Protocols = engine.serverProtocols
if engine.serverProtocols.HTTP2() || engine.serverProtocols.UnencryptedHTTP2() {
func cloneServerProtocols(protocols *http.Protocols) *http.Protocols {
if protocols == nil {
return nil
}
cloned := *protocols
return &cloned
}
func applyServerProtocols(srv *http.Server, protocols *http.Protocols) {
if protocols != nil {
srv.Protocols = cloneServerProtocols(protocols)
if srv.Protocols.HTTP2() || srv.Protocols.UnencryptedHTTP2() {
if err := configureHTTP2ExtendedConnectServer(srv); err != nil {
panic(err)
}
@ -416,6 +423,11 @@ func (engine *Engine) applyDefaultServerConfig(srv *http.Server) {
}
}
// applyDefaultServerConfig 应用框架的默认配置到 http.Server
func (engine *Engine) applyDefaultServerConfig(srv *http.Server) {
applyServerProtocols(srv, engine.serverProtocols)
}
// 配置全局Req Body大小限制
func (engine *Engine) SetGlobalMaxRequestBodySize(size int64) {
engine.GlobalMaxRequestBodySize = size