config.go 690 B

1234567891011121314151617181920212223242526272829
  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. }
  19. // ToServerConfig converts Config to ServerConfig for internal use
  20. func (c *Config) ToServerConfig() ServerConfig {
  21. return ServerConfig{
  22. AllowedOrigins: c.AllowedOrigins,
  23. RequestTimeout: c.RequestTimeout,
  24. }
  25. }