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 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. MOTD string
  23. Name string
  24. }
  25. Operator map[string]*PassConfig
  26. Debug struct {
  27. Net bool
  28. Client bool
  29. Channel bool
  30. Server bool
  31. }
  32. }
  33. func (conf *Config) Operators() map[string][]byte {
  34. operators := make(map[string][]byte)
  35. for name, opConf := range conf.Operator {
  36. operators[name] = opConf.PasswordBytes()
  37. }
  38. return operators
  39. }
  40. func LoadConfig(filename string) (config *Config, err error) {
  41. config = &Config{}
  42. err = gcfg.ReadFileInto(config, filename)
  43. if err != nil {
  44. return
  45. }
  46. if config.Server.Name == "" {
  47. err = errors.New("server.name missing")
  48. return
  49. }
  50. if config.Server.Database == "" {
  51. err = errors.New("server.database missing")
  52. return
  53. }
  54. if len(config.Server.Listen) == 0 {
  55. err = errors.New("server.listen missing")
  56. return
  57. }
  58. return
  59. }