appservice.go 808 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package config
  2. type appservice struct {
  3. Address string `yaml:"address"`
  4. Hostname string `yaml:"hostname"`
  5. Port uint16 `yaml:"port"`
  6. ID string `yaml:"id"`
  7. Bot bot `yaml:"bot"`
  8. ASToken string `yaml:"as_token"`
  9. HSToken string `yaml:"hs_token"`
  10. }
  11. func (a *appservice) validate() error {
  12. if a.ID == "" {
  13. a.ID = "discord"
  14. }
  15. if a.Address == "" {
  16. a.Address = "http://localhost:29350"
  17. }
  18. if a.Hostname == "" {
  19. a.Hostname = "0.0.0.0"
  20. }
  21. if a.Port == 0 {
  22. a.Port = 29350
  23. }
  24. if err := a.Bot.validate(); err != nil {
  25. return err
  26. }
  27. return nil
  28. }
  29. func (a *appservice) UnmarshalYAML(unmarshal func(interface{}) error) error {
  30. type rawAppservice appservice
  31. raw := rawAppservice{}
  32. if err := unmarshal(&raw); err != nil {
  33. return err
  34. }
  35. *a = appservice(raw)
  36. return a.validate()
  37. }