config.go 474 B

123456789101112131415161718192021
  1. package server
  2. import "time"
  3. // Config holds the server configuration
  4. type Config struct {
  5. Port int `yaml:"port"`
  6. RequestTimeout time.Duration `yaml:"request_timeout"` // in seconds
  7. AllowedOrigins []string `yaml:"allowed_origins"`
  8. }
  9. // Validate implements the config.Validator interface
  10. func (c *Config) Validate() error {
  11. if c.Port == 0 {
  12. c.Port = 8080
  13. }
  14. if c.RequestTimeout == 0 {
  15. c.RequestTimeout = 30 * time.Second
  16. }
  17. return nil
  18. }