Files
mautrix-discord/config/appservice.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

40 lines
652 B
Go

package config
type appservice struct {
Address string `yaml:"address"`
Hostname string `yaml:"hostname"`
Port uint16 `yaml:"port"`
ID string `yaml:"id"`
Bot bot `yaml:"bot"`
ASToken string `yaml:"as_token"`
HSToken string `yaml:"hs_token"`
}
func (a *appservice) validate() error {
if a.ID == "" {
a.ID = "discord"
}
if err := a.Bot.validate(); err != nil {
return err
}
return nil
}
func (a *appservice) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawAppservice appservice
raw := rawAppservice{}
if err := unmarshal(&raw); err != nil {
return err
}
*a = appservice(raw)
return a.validate()
}