defines the method to customize http server (#2171)

This commit is contained in:
sniperwzq
2023-03-11 23:15:00 +08:00
committed by GitHub
parent 211b9498ef
commit 3e093bf34e
2 changed files with 21 additions and 9 deletions

View File

@@ -301,21 +301,25 @@ func (ng *engine) signatureVerifier(signature signatureSetting) (func(chain.Chai
}, nil
}
func (ng *engine) start(router httpx.Router) error {
func (ng *engine) start(router httpx.Router, opts ...internal.StartOption) error {
if err := ng.bindRoutes(router); err != nil {
return err
}
opts = append(opts, ng.withTimeout())
if len(ng.conf.CertFile) == 0 && len(ng.conf.KeyFile) == 0 {
return internal.StartHttp(ng.conf.Host, ng.conf.Port, router, ng.withTimeout())
return internal.StartHttp(ng.conf.Host, ng.conf.Port, router, opts...)
}
opts = append(opts, func(svr *http.Server) {
if ng.tlsConfig != nil {
svr.TLSConfig = ng.tlsConfig
}
})
return internal.StartHttps(ng.conf.Host, ng.conf.Port, ng.conf.CertFile,
ng.conf.KeyFile, router, func(svr *http.Server) {
if ng.tlsConfig != nil {
svr.TLSConfig = ng.tlsConfig
}
}, ng.withTimeout())
ng.conf.KeyFile, router, opts...)
}
func (ng *engine) use(middleware Middleware) {