2020-10-23 20:07:15 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoadConfig(path string) (c Configuration, err error) {
|
|
|
|
var file *ini.File
|
|
|
|
file, err = ini.LoadSources(ini.LoadOptions{
|
2020-10-25 15:36:34 +00:00
|
|
|
AllowShadows: true,
|
|
|
|
AllowNonUniqueSections: true,
|
2020-10-23 20:07:15 +01:00
|
|
|
}, path)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if s := file.Section("Host"); s != nil {
|
|
|
|
err = s.MapTo(&c.Host)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var sections []*ini.Section
|
|
|
|
sections, err = file.SectionsByName("Peer")
|
|
|
|
|
|
|
|
for _, s := range sections {
|
|
|
|
if s == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
p := Peer{}
|
|
|
|
err = s.MapTo(&p)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Peers = append(c.Peers, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = c.Validate()
|
|
|
|
return
|
|
|
|
}
|