mirror of
https://github.com/nabbar/golib.git
synced 2025-12-24 11:51:02 +08:00
Fix issue #21
This commit is contained in:
@@ -55,6 +55,7 @@ const (
|
||||
)
|
||||
|
||||
type modelServer struct {
|
||||
tmo time.Duration
|
||||
ssl *tls.Config
|
||||
srv *http.Server
|
||||
hdl http.Handler
|
||||
@@ -64,6 +65,9 @@ type modelServer struct {
|
||||
}
|
||||
|
||||
type HTTPServer interface {
|
||||
SetTIdleTimeout(idleTimeout time.Duration)
|
||||
GetTIdleTimeout() time.Duration
|
||||
|
||||
GetBindable() string
|
||||
GetExpose() string
|
||||
IsRunning() bool
|
||||
@@ -77,6 +81,7 @@ type HTTPServer interface {
|
||||
|
||||
func NewServer(listen, expose string, handler http.Handler, tlsConfig *tls.Config) HTTPServer {
|
||||
srv := &modelServer{
|
||||
tmo: TIMEOUT_30_SEC,
|
||||
hdl: handler,
|
||||
ssl: tlsConfig,
|
||||
}
|
||||
@@ -196,21 +201,23 @@ func (srv *modelServer) Listen() {
|
||||
}
|
||||
|
||||
err := http2.ConfigureServer(srv.srv, cnf)
|
||||
FatalLevel.Logf("Configuring Server '%s' Error: %v", srv.host, err)
|
||||
FatalLevel.LogErrorCtxf(DebugLevel, "Configuring Server '%s'", err, srv.host)
|
||||
|
||||
go func() {
|
||||
if srv.ssl == nil || !certif.CheckCertificates() {
|
||||
InfoLevel.Logf("Server '%s' is starting with bindable: %s", srv.host, srv.GetBindable())
|
||||
if err := srv.srv.ListenAndServe(); err != nil {
|
||||
FatalLevel.Logf("Listen Server '%s' Error: %v", srv.host, err)
|
||||
return
|
||||
}
|
||||
|
||||
err := srv.srv.ListenAndServe()
|
||||
|
||||
FatalLevel.LogErrorCtxf(NilLevel, "Listen Server '%s'", err, srv.host)
|
||||
|
||||
} else {
|
||||
|
||||
InfoLevel.Logf("TLS Server '%s' is starting with bindable: %s", srv.host, srv.GetBindable())
|
||||
if err := srv.srv.ListenAndServeTLS("", ""); err != nil {
|
||||
FatalLevel.Logf("Listen TLS Server '%s' Error: %v", srv.host, err)
|
||||
return
|
||||
}
|
||||
|
||||
err := srv.srv.ListenAndServeTLS("", "")
|
||||
|
||||
FatalLevel.LogErrorCtxf(NilLevel, "Listen Server '%s'", err, srv.host)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -256,3 +263,11 @@ func (srv *modelServer) Shutdown() {
|
||||
func (srv *modelServer) IsRunning() bool {
|
||||
return srv.srv != nil
|
||||
}
|
||||
|
||||
func (srv *modelServer) SetTIdleTimeout(idleTimeout time.Duration) {
|
||||
srv.tmo = idleTimeout
|
||||
}
|
||||
|
||||
func (srv modelServer) GetTIdleTimeout() time.Duration {
|
||||
return srv.tmo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user