Skip to content

Commit

Permalink
config: read tcpKeepAlive from file (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Feb 21, 2019
1 parent e21426f commit 326e9fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions testdata/config1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ server:
writeTimeout: 6s
idleTimeout: 30s
reusePort: true
tcpKeepAlive: 1m
gracefulShutdown:
timeout: 1m
wait: 5s
Expand Down

0 comments on commit 326e9fb

Please sign in to comment.