homeserver.go 834 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package config
  2. import (
  3. "errors"
  4. )
  5. var (
  6. ErrHomeserverNoAddress = errors.New("no homeserver address specified")
  7. ErrHomeserverNoDomain = errors.New("no homeserver domain specified")
  8. )
  9. type homeserver struct {
  10. Address string `yaml:"address"`
  11. Domain string `yaml:"domain"`
  12. Asmux bool `yaml:"asmux"`
  13. StatusEndpoint string `yaml:"status_endpoint"`
  14. AsyncMedia bool `yaml:"async_media"`
  15. }
  16. func (h *homeserver) validate() error {
  17. if h.Address == "" {
  18. return ErrHomeserverNoAddress
  19. }
  20. if h.Domain == "" {
  21. return ErrHomeserverNoDomain
  22. }
  23. return nil
  24. }
  25. func (h *homeserver) UnmarshalYAML(unmarshal func(interface{}) error) error {
  26. type rawHomeserver homeserver
  27. raw := rawHomeserver{}
  28. if err := unmarshal(&raw); err != nil {
  29. return err
  30. }
  31. *h = homeserver(raw)
  32. return h.validate()
  33. }