59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Server ServerConfig `yaml:"server"`
|
|
Auth AuthConfig `yaml:"auth"`
|
|
TLS TLSConfig `yaml:"tls"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
BindAddress string `yaml:"bind_address"`
|
|
ReadTimeout time.Duration `yaml:"read_timeout"`
|
|
WriteTimeout time.Duration `yaml:"write_timeout"`
|
|
}
|
|
|
|
type AuthConfig struct {
|
|
Mode string `yaml:"mode"`
|
|
Token string `yaml:"token,omitempty"`
|
|
}
|
|
|
|
type TLSConfig struct {
|
|
Enabled bool `yaml:"enabled"`
|
|
CertFile string `yaml:"cert_file"`
|
|
KeyFile string `yaml:"key_file"`
|
|
}
|
|
|
|
type ConfigLoader interface {
|
|
LoadConfig() (*Config, error)
|
|
}
|
|
|
|
func DefaultConfig() *Config {
|
|
return &Config{
|
|
Server: ServerConfig{
|
|
BindAddress: ":8080",
|
|
ReadTimeout: 15 * time.Second,
|
|
WriteTimeout: 15 * time.Second,
|
|
},
|
|
Auth: AuthConfig{
|
|
Mode: "none",
|
|
},
|
|
TLS: TLSConfig{
|
|
Enabled: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c Config) applyDefaults() *Config {
|
|
if c.Server.BindAddress == "" {
|
|
c.Server.BindAddress = ":8080"
|
|
}
|
|
if c.Auth.Mode == "" {
|
|
c.Auth.Mode = "none"
|
|
}
|
|
return &c
|
|
}
|