Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

config.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package irc
  2. import (
  3. "code.google.com/p/gcfg"
  4. "errors"
  5. "log"
  6. )
  7. type PassConfig struct {
  8. Password string
  9. }
  10. func (conf *PassConfig) PasswordBytes() []byte {
  11. bytes, err := DecodePassword(conf.Password)
  12. if err != nil {
  13. log.Fatal("decode password error: ", err)
  14. }
  15. return bytes
  16. }
  17. type Config struct {
  18. Server struct {
  19. PassConfig
  20. Database string
  21. Listen []string
  22. Log string
  23. MOTD string
  24. Name string
  25. }
  26. Operator map[string]*PassConfig
  27. Theater map[string]*PassConfig
  28. }
  29. func (conf *Config) Operators() map[Name][]byte {
  30. operators := make(map[Name][]byte)
  31. for name, opConf := range conf.Operator {
  32. operators[NewName(name)] = opConf.PasswordBytes()
  33. }
  34. return operators
  35. }
  36. func (conf *Config) Theaters() map[Name][]byte {
  37. theaters := make(map[Name][]byte)
  38. for s, theaterConf := range conf.Theater {
  39. name := NewName(s)
  40. if !name.IsChannel() {
  41. log.Fatal("config uses a non-channel for a theater!")
  42. }
  43. theaters[name] = theaterConf.PasswordBytes()
  44. }
  45. return theaters
  46. }
  47. func LoadConfig(filename string) (config *Config, err error) {
  48. config = &Config{}
  49. err = gcfg.ReadFileInto(config, filename)
  50. if err != nil {
  51. return
  52. }
  53. if config.Server.Name == "" {
  54. err = errors.New("server.name missing")
  55. return
  56. }
  57. if config.Server.Database == "" {
  58. err = errors.New("server.database missing")
  59. return
  60. }
  61. if len(config.Server.Listen) == 0 {
  62. err = errors.New("server.listen missing")
  63. return
  64. }
  65. return
  66. }