gospt/config/config.go
jjohnstondev f8d877cac0 initial
2023-01-06 23:40:39 -08:00

40 lines
854 B
Go

package config
import (
"path/filepath"
"github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigyaml"
)
var Values struct {
ClientId string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
DeviceId string `yaml:"device_id"`
Port int `yaml:"port"`
}
func LoadConfig(configDir string) {
yamlDecoder := aconfigyaml.New()
loader := aconfig.LoaderFor(&Values, aconfig.Config{
AllowUnknownFields: true,
AllowUnknownEnvs: true,
AllowUnknownFlags: true,
SkipFlags: true,
DontGenerateTags: true,
MergeFiles: true,
EnvPrefix: "",
FlagPrefix: "",
Files: []string{
filepath.Join(configDir, "client.yml"),
},
FileDecoders: map[string]aconfig.FileDecoder{
".yml": yamlDecoder,
},
})
if err := loader.Load(); err != nil {
panic(err)
}
}