conf.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "github.com/BurntSushi/toml"
  7. )
  8. var (
  9. // Conf crocodile conf
  10. Conf *conf
  11. )
  12. // Init Config
  13. func Init(conf string) {
  14. _, err := toml.DecodeFile(conf, &Conf)
  15. if err != nil {
  16. fmt.Printf("Err %v", err)
  17. os.Exit(1)
  18. }
  19. }
  20. type conf struct {
  21. Server server
  22. DB db
  23. Udp udp
  24. Mail mail
  25. Log log
  26. }
  27. type server struct {
  28. Thread int
  29. ValidTime int
  30. StatusDays int
  31. LastId string
  32. }
  33. type udp struct {
  34. LocPort string
  35. Next udpNext
  36. }
  37. type udpNext struct {
  38. Addr string
  39. Port int
  40. Stype string
  41. }
  42. type mail struct {
  43. Send bool
  44. To string
  45. Api string
  46. }
  47. // Log Config
  48. type log struct {
  49. LogPath string
  50. MaxSize int
  51. Compress bool
  52. MaxAge int
  53. MaxBackups int
  54. LogLevel string
  55. Format string
  56. }
  57. type db struct {
  58. MongoB mgo
  59. MongoP mgo
  60. }
  61. type mgo struct {
  62. Addr string
  63. Dbname string
  64. Coll string
  65. Size int
  66. User string
  67. Password string
  68. }
  69. type duration struct {
  70. time.Duration
  71. }
  72. // UnmarshalText parse 10s to time.Time
  73. func (d *duration) UnmarshalText(text []byte) error {
  74. var err error
  75. d.Duration, err = time.ParseDuration(string(text))
  76. return err
  77. }