feat: add config loading with YAML, env override, and hot-reload
This commit is contained in:
53
internal/config/config.go
Normal file
53
internal/config/config.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// DoubaoConfig holds 火山引擎豆包 ASR credentials.
|
||||
type DoubaoConfig struct {
|
||||
AppKey string `yaml:"app_key"`
|
||||
AccessKey string `yaml:"access_key"`
|
||||
ResourceID string `yaml:"resource_id"`
|
||||
}
|
||||
|
||||
// ServerConfig holds server settings.
|
||||
type ServerConfig struct {
|
||||
Port int `yaml:"port"`
|
||||
TLSAuto bool `yaml:"tls_auto"`
|
||||
}
|
||||
|
||||
// Config is the top-level configuration.
|
||||
type Config struct {
|
||||
Doubao DoubaoConfig `yaml:"doubao"`
|
||||
Server ServerConfig `yaml:"server"`
|
||||
}
|
||||
|
||||
// defaults returns a Config with default values.
|
||||
func defaults() Config {
|
||||
return Config{
|
||||
Doubao: DoubaoConfig{
|
||||
ResourceID: "volc.seedasr.sauc.duration",
|
||||
},
|
||||
Server: ServerConfig{
|
||||
Port: 8443,
|
||||
TLSAuto: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// global holds the current config atomically for concurrent reads.
|
||||
var global atomic.Value
|
||||
|
||||
// Get returns the current config snapshot. Safe for concurrent use.
|
||||
func Get() Config {
|
||||
if v := global.Load(); v != nil {
|
||||
return v.(Config)
|
||||
}
|
||||
return defaults()
|
||||
}
|
||||
|
||||
// store updates the global config.
|
||||
func store(cfg Config) {
|
||||
global.Store(cfg)
|
||||
}
|
||||
Reference in New Issue
Block a user