40 lines
645 B
Go
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
|
|
}
|