combluotion/config/load.go
Dan Jones 6f06adc37d ♻️ Refactor config
Make it easier to setup stores
2025-01-26 20:07:45 -06:00

40 lines
645 B
Go

package config
import "github.com/BurntSushi/toml"
type confToml struct {
Name string
Env Env
BaseURL string `toml:"base_url"`
Stores storeSettings `toml:"stores"`
}
type storeSettings struct {
Store string
Settings map[string]toml.Primitive
}
func LoadFromToml(path string) (Config, error) {
var c confToml
md, err := toml.DecodeFile(path, &c)
if err != nil {
return nil, err
}
conf := config{
name: c.Name,
env: c.Env,
baseURL: c.BaseURL,
md: md,
}
st := stores{
store: c.Stores.Store,
settings: c.Stores.Settings,
conf: &conf,
}
conf.stores = st
return conf, nil
}