You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.go 849B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package irc
  2. import (
  3. "encoding/json"
  4. "os"
  5. )
  6. type Config struct {
  7. Debug map[string]bool
  8. Listeners []ListenerConfig
  9. MOTD string
  10. Name string
  11. Operators []OperatorConfig
  12. Password string
  13. }
  14. type OperatorConfig struct {
  15. Name string
  16. Password string
  17. }
  18. type ListenerConfig struct {
  19. Net string
  20. Address string
  21. Key string
  22. Certificate string
  23. }
  24. func (config *ListenerConfig) IsTLS() bool {
  25. return (config.Key != "") && (config.Certificate != "")
  26. }
  27. func LoadConfig() (config *Config, err error) {
  28. config = &Config{}
  29. file, err := os.Open("ergonomadic.json")
  30. if err != nil {
  31. return
  32. }
  33. defer file.Close()
  34. decoder := json.NewDecoder(file)
  35. err = decoder.Decode(config)
  36. if err != nil {
  37. return
  38. }
  39. for _, lconf := range config.Listeners {
  40. if lconf.Net == "" {
  41. lconf.Net = "tcp"
  42. }
  43. }
  44. return
  45. }