package config

This commit is contained in:
henk
2026-05-15 14:22:16 +02:00
parent 1254f70a5f
commit 107c23a29d
7 changed files with 180 additions and 2 deletions

58
internal/config/config.go Normal file
View File

@@ -0,0 +1,58 @@
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
}