Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

config.go 1.1KB

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