Skip to content

Commit

Permalink
feat(#33): use server timeouts from config, add defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumpy-Squirrel committed Jul 14, 2024
1 parent e537f3d commit 6bc2504
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ func (c *Config) AddDefaults() {
if c.Server.Port == 0 {
c.Server.Port = 8081
}
if c.Server.IdleTimeout <= 0 {
c.Server.IdleTimeout = 30
}
if c.Server.ReadTimeout <= 0 {
c.Server.ReadTimeout = 30
}
if c.Server.WriteTimeout <= 0 {
c.Server.WriteTimeout = 30
}
}
7 changes: 3 additions & 4 deletions internal/web/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func NewServer(conf *config.Config, baseCtx context.Context) Server {

s.ctx = baseCtx

// TODO should be in config so it is obvious what they are set to
s.idleTimeout = time.Minute
s.readTimeout = time.Minute
s.writeTimeout = time.Minute
s.idleTimeout = time.Duration(conf.Server.IdleTimeout) * time.Second
s.readTimeout = time.Duration(conf.Server.ReadTimeout) * time.Second
s.writeTimeout = time.Duration(conf.Server.WriteTimeout) * time.Second

s.host = conf.Server.BaseAddress
s.port = conf.Server.Port
Expand Down

0 comments on commit 6bc2504

Please sign in to comment.