diff --git a/app.go b/app.go index 5ba1eed..b306086 100644 --- a/app.go +++ b/app.go @@ -128,7 +128,7 @@ func (app *App) Shutdown(ctx context.Context) error { return app.srv.Shutdown(ctx) } -// TCPKeepAlive sets tcp keep-alive when using app.ListenAndServe +// TCPKeepAlive sets tcp keep-alive interval when using app.ListenAndServe func (app *App) TCPKeepAlive(d time.Duration) *App { app.tcpKeepAlive = d return app diff --git a/config.go b/config.go index 9247377..0feb7ed 100644 --- a/config.go +++ b/config.go @@ -18,7 +18,8 @@ type AppConfig struct { ReadHeaderTimeout string `yaml:"readHeaderTimeout" json:"readHeaderTimeout"` WriteTimeout string `yaml:"writeTimeout" json:"writeTimeout"` IdleTimeout string `yaml:"idleTimeout" json:"idleTimeout"` - ReusePort bool `yaml:"reusePort" json:"reusePort"` + ReusePort *bool `yaml:"reusePort" json:"reusePort"` + TCPKeepAlive string `yaml:"tcpKeepAlive" json:"tcpKeepAlive"` GracefulShutdown *GracefulShutdown `yaml:"gracefulShutdown" json:"gracefulShutdown"` TLS *TLS `yaml:"tls" json:"tls"` HTTPSRedirect *HTTPSRedirect `yaml:"httpsRedirect" json:"httpsRedirect"` @@ -86,9 +87,10 @@ func (app *App) Config(config AppConfig) *App { parseDuration(server.ReadHeaderTimeout, &app.srv.ReadHeaderTimeout) parseDuration(server.WriteTimeout, &app.srv.WriteTimeout) parseDuration(server.IdleTimeout, &app.srv.IdleTimeout) + parseDuration(server.TCPKeepAlive, &app.tcpKeepAlive) - if server.ReusePort { - app.ReusePort(true) + if server.ReusePort != nil { + app.reusePort = *server.ReusePort } if t := server.TLS; t != nil { diff --git a/config_test.go b/config_test.go index 01fe90c..548a74f 100644 --- a/config_test.go +++ b/config_test.go @@ -35,6 +35,7 @@ func TestConfig(t *testing.T) { assert.Equal(t, app.srv.ReadHeaderTimeout, 5*time.Second) assert.Equal(t, app.srv.WriteTimeout, 6*time.Second) assert.Equal(t, app.srv.IdleTimeout, 30*time.Second) + assert.Equal(t, app.tcpKeepAlive, time.Minute) assert.True(t, app.reusePort) assert.Len(t, app.srv.TLSConfig.Certificates, 1) diff --git a/testdata/config1.yaml b/testdata/config1.yaml index 7acb33c..d8a99fe 100644 --- a/testdata/config1.yaml +++ b/testdata/config1.yaml @@ -23,6 +23,7 @@ server: writeTimeout: 6s idleTimeout: 30s reusePort: true + tcpKeepAlive: 1m gracefulShutdown: timeout: 1m wait: 5s