33 lines
1.6 KiB
Go
33 lines
1.6 KiB
Go
package hws
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.haelnorr.com/h/golib/env"
|
|
)
|
|
|
|
type Config struct {
|
|
Host string `ezconf:"HWS_HOST,description:Host to listen on,default:127.0.0.1"`
|
|
Port uint64 `ezconf:"HWS_PORT,description:Port to listen on,default:3000"`
|
|
GZIP bool `ezconf:"HWS_GZIP,description:Flag for GZIP compression on requests,default:false"`
|
|
ReadHeaderTimeout time.Duration `ezconf:"HWS_READ_HEADER_TIMEOUT,description:Timeout for reading request headers in seconds,default:2"`
|
|
WriteTimeout time.Duration `ezconf:"HWS_WRITE_TIMEOUT,description:Timeout for writing requests in seconds,default:10"`
|
|
IdleTimeout time.Duration `ezconf:"HWS_IDLE_TIMEOUT,description:Timeout for idle connections in seconds,default:120"`
|
|
ShutdownDelay time.Duration `ezconf:"HWS_SHUTDOWN_DELAY,description:Delay in seconds before server shuts down when Shutdown is called,default:5"`
|
|
}
|
|
|
|
// ConfigFromEnv returns a Config struct loaded from the environment variables
|
|
func ConfigFromEnv() (*Config, error) {
|
|
cfg := &Config{
|
|
Host: env.String("HWS_HOST", "127.0.0.1"),
|
|
Port: env.UInt64("HWS_PORT", 3000),
|
|
GZIP: env.Bool("HWS_GZIP", false),
|
|
ReadHeaderTimeout: time.Duration(env.Int("HWS_READ_HEADER_TIMEOUT", 2)) * time.Second,
|
|
WriteTimeout: time.Duration(env.Int("HWS_WRITE_TIMEOUT", 10)) * time.Second,
|
|
IdleTimeout: time.Duration(env.Int("HWS_IDLE_TIMEOUT", 120)) * time.Second,
|
|
ShutdownDelay: time.Duration(env.Int("HWS_SHUTDOWN_DELAY", 5)) * time.Second,
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|