Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

config.go 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Wslisten string
  23. Log string
  24. MOTD string
  25. Name string
  26. }
  27. Operator map[string]*PassConfig
  28. Theater map[string]*PassConfig
  29. }
  30. func (conf *Config) Operators() map[Name][]byte {
  31. operators := make(map[Name][]byte)
  32. for name, opConf := range conf.Operator {
  33. operators[NewName(name)] = opConf.PasswordBytes()
  34. }
  35. return operators
  36. }
  37. func (conf *Config) Theaters() map[Name][]byte {
  38. theaters := make(map[Name][]byte)
  39. for s, theaterConf := range conf.Theater {
  40. name := NewName(s)
  41. if !name.IsChannel() {
  42. log.Fatal("config uses a non-channel for a theater!")
  43. }
  44. theaters[name] = theaterConf.PasswordBytes()
  45. }
  46. return theaters
  47. }
  48. func LoadConfig(filename string) (config *Config, err error) {
  49. config = &Config{}
  50. err = gcfg.ReadFileInto(config, filename)
  51. if err != nil {
  52. return
  53. }
  54. if config.Server.Name == "" {
  55. err = errors.New("server.name missing")
  56. return
  57. }
  58. if config.Server.Database == "" {
  59. err = errors.New("server.database missing")
  60. return
  61. }
  62. if len(config.Server.Listen) == 0 {
  63. err = errors.New("server.listen missing")
  64. return
  65. }
  66. return
  67. }