mautrix-discord/config/bot.go
Gary Kramlich 2b63ddc6b8 Rename the config structs setDefaults to validate
This allows us to check for some required values and give an easy to respond
to error at startup rather than a lot of validation during run time.
2021-11-19 16:53:43 -06:00

33 lines
528 B
Go

package config
type bot struct {
Username string `yaml:"username"`
Displayname string `yaml:"displayname"`
Avatar string `yaml:"avatar"`
}
func (b *bot) validate() error {
if b.Username == "" {
b.Username = "discordbot"
}
if b.Displayname == "" {
b.Displayname = "Discord Bridge Bot"
}
return nil
}
func (b *bot) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawBot bot
raw := rawBot{}
if err := unmarshal(&raw); err != nil {
return err
}
*b = bot(raw)
return b.validate()
}