mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-12 05:54:25 +00:00
feat(config): add multiple server instances support
- Add ServersConfig and ServerInstanceConfig structs - Support configuring multiple named server instances - Add global timeout defaults with per-instance overrides - Add TLS configuration options (SSL cert/key, self-signed, AutoTLS) - Add validation for server configurations - Add helper methods for applying defaults and getting default server - Add conversion helper to avoid import cycles
This commit is contained in:
47
pkg/server/config_helper.go
Normal file
47
pkg/server/config_helper.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/bitechdev/ResolveSpec/pkg/config"
|
||||
)
|
||||
|
||||
// FromConfigInstanceToServerConfig converts a config.ServerInstanceConfig to server.Config
|
||||
// The handler must be provided separately as it cannot be serialized
|
||||
func FromConfigInstanceToServerConfig(sic *config.ServerInstanceConfig, handler http.Handler) Config {
|
||||
cfg := Config{
|
||||
Name: sic.Name,
|
||||
Host: sic.Host,
|
||||
Port: sic.Port,
|
||||
Description: sic.Description,
|
||||
Handler: handler,
|
||||
GZIP: sic.GZIP,
|
||||
|
||||
SSLCert: sic.SSLCert,
|
||||
SSLKey: sic.SSLKey,
|
||||
SelfSignedSSL: sic.SelfSignedSSL,
|
||||
AutoTLS: sic.AutoTLS,
|
||||
AutoTLSDomains: sic.AutoTLSDomains,
|
||||
AutoTLSCacheDir: sic.AutoTLSCacheDir,
|
||||
AutoTLSEmail: sic.AutoTLSEmail,
|
||||
}
|
||||
|
||||
// Apply timeouts (use pointers to override, or use zero values for defaults)
|
||||
if sic.ShutdownTimeout != nil {
|
||||
cfg.ShutdownTimeout = *sic.ShutdownTimeout
|
||||
}
|
||||
if sic.DrainTimeout != nil {
|
||||
cfg.DrainTimeout = *sic.DrainTimeout
|
||||
}
|
||||
if sic.ReadTimeout != nil {
|
||||
cfg.ReadTimeout = *sic.ReadTimeout
|
||||
}
|
||||
if sic.WriteTimeout != nil {
|
||||
cfg.WriteTimeout = *sic.WriteTimeout
|
||||
}
|
||||
if sic.IdleTimeout != nil {
|
||||
cfg.IdleTimeout = *sic.IdleTimeout
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
@@ -501,7 +501,7 @@ func (s *serverInstance) Start() error {
|
||||
|
||||
if useTLS {
|
||||
protocol = "HTTPS"
|
||||
logger.Info("Starting %s server '%s' on %s", protocol, s.cfg.Name, s.Addr())
|
||||
logger.Info("Starting %s server - Name: '%s', Address: %s, Port: %d", protocol, s.cfg.Name, s.cfg.Host, s.cfg.Port)
|
||||
|
||||
// For AutoTLS, we need to use a TLS listener
|
||||
if s.cfg.AutoTLS {
|
||||
@@ -519,7 +519,7 @@ func (s *serverInstance) Start() error {
|
||||
err = s.gracefulServer.server.ListenAndServeTLS(s.certFile, s.keyFile)
|
||||
}
|
||||
} else {
|
||||
logger.Info("Starting %s server '%s' on %s", protocol, s.cfg.Name, s.Addr())
|
||||
logger.Info("Starting %s server - Name: '%s', Address: %s, Port: %d", protocol, s.cfg.Name, s.cfg.Host, s.cfg.Port)
|
||||
err = s.gracefulServer.server.ListenAndServe()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user