package config import ( "gopkg.in/yaml.v2" "io" "bytes" "github.com/imdario/mergo" ) type Config struct { XMPP XMPPConfig `yaml:"xmpp,omitempty"` } type XMPPConfig struct { Address string Jid string Credential string Insecure bool MUCs []string } func Load(r io.Reader) (c Config, err error) { buf := new(bytes.Buffer) buf.ReadFrom(r) if err = yaml.Unmarshal(buf.Bytes(), &c); err != nil { return } mergo.Merge(&c, Config{ XMPP: XMPPConfig{ Address: "localhost:5222", Jid: "user@localhost", Credential: "password", Insecure: true, }, }) return } func Save(w io.Writer, c Config) (err error) { out, err := yaml.Marshal(c) if err != nil { return } _, err = w.Write(out) return }