♻️ Refactor config
Make it easier to setup stores
This commit is contained in:
parent
ecae0d5f83
commit
6f06adc37d
12 changed files with 623 additions and 81 deletions
|
|
@ -2,7 +2,39 @@ package config
|
|||
|
||||
import "github.com/BurntSushi/toml"
|
||||
|
||||
func LoadFromToml(path string) (c Config, err error) {
|
||||
_, err = toml.DecodeFile(path, &c)
|
||||
return
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue