go(settings): expose default server timeouts
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-08-05 14:25:34 +02:00
parent 4ccec7857d
commit e941e73222
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI
2 changed files with 19 additions and 7 deletions

@ -6,7 +6,6 @@ package app
import ( import (
"encoding/hex" "encoding/hex"
"net/http" "net/http"
"time"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session" "github.com/labstack/echo-contrib/session"
@ -46,8 +45,8 @@ func (a *App) SetEchoSettings() {
// })) // }))
// TODO: make this configurable. // TODO: make this configurable.
e.Server.WriteTimeout = 30 * time.Second e.Server.WriteTimeout = a.setting.DefaultServerWriteTimeout()
e.Server.ReadHeaderTimeout = 30 * time.Second e.Server.ReadHeaderTimeout = a.setting.DefaultServerReadHeaderTimeout()
if a.setting.HTTPRateLimitEnabled() { if a.setting.HTTPRateLimitEnabled() {
limit := rate.Limit(a.setting.HTTPRateLimit()) limit := rate.Limit(a.setting.HTTPRateLimit())

@ -5,6 +5,7 @@ package settings
import ( import (
"os" "os"
"time"
"git.dotya.ml/mirre-mt/pcmt/config" "git.dotya.ml/mirre-mt/pcmt/config"
"git.dotya.ml/mirre-mt/pcmt/slogging" "git.dotya.ml/mirre-mt/pcmt/slogging"
@ -41,10 +42,12 @@ type Settings struct {
} }
const ( const (
appName = "pcmt" appName = "pcmt"
defaultPort = 3000 defaultPort = 3000
defaultSessionMaxAge = 86400 // seconds. defaultSessionMaxAge = 86400 // seconds.
defaultHTTPDomain = "localhost" defaultHTTPDomain = "localhost"
defaultServerWriteTimeout = 30 * time.Second
defaultServerReadHeaderTimeout = 30 * time.Second
) )
// cleantgt is a list of ENV vars pertaining to pcmt. // cleantgt is a list of ENV vars pertaining to pcmt.
@ -63,6 +66,16 @@ func New() *Settings {
return &Settings{} return &Settings{}
} }
// DefaultServerWriteTimeout returns the server default write timeout.
func (s *Settings) DefaultServerWriteTimeout() time.Duration {
return defaultServerWriteTimeout
}
// DefaultServerReadHeaderTimeout returns the server default read header timeout.
func (s *Settings) DefaultServerReadHeaderTimeout() time.Duration {
return defaultServerReadHeaderTimeout
}
// Consolidate reconciles whatever values are set in config and via flags and // Consolidate reconciles whatever values are set in config and via flags and
// sets it to one place that should be regarded as a single source of truth - // sets it to one place that should be regarded as a single source of truth -
// the settings struct. Order of preference for values is (from higher to // the settings struct. Order of preference for values is (from higher to