config.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package config
  2. import (
  3. "gopkg.in/yaml.v2"
  4. "os"
  5. "sync"
  6. )
  7. var (
  8. instance *config
  9. once sync.Once
  10. )
  11. func init() {
  12. once.Do(func() {
  13. var conf config
  14. path, _ := os.Getwd()
  15. filePath := path + "/config/config.yaml"
  16. if f, err := os.Open(filePath); err != nil {
  17. panic(err)
  18. } else {
  19. err := yaml.NewDecoder(f).Decode(&conf)
  20. if err != nil {
  21. panic(err)
  22. }
  23. }
  24. instance = &conf
  25. })
  26. }
  27. // 获取配置文档实例
  28. func Instance() *config {
  29. return instance
  30. }
  31. type config struct {
  32. Server server `yaml:"server"`
  33. Database database `yaml:"database"`
  34. Redis redis `yaml:"redis"`
  35. Logger logger `yaml:"logger"`
  36. Minio minio `yaml:"minio"`
  37. Foreign foreign `yaml:"foreign"`
  38. MonitNotice monitNotice `yaml:"monit-notice"`
  39. Es es `yaml:"es"`
  40. }
  41. type server struct {
  42. Address string `yaml:"address"`
  43. CodeEnabled bool `yaml:"code_enabled"`
  44. TokenSign string `yaml:"token_sign"`
  45. }
  46. type database struct {
  47. Host string `yaml:"host"`
  48. Auth string `yaml:"Auth"`
  49. Password string `yaml:"password"`
  50. Port string `yaml:"port"`
  51. Name string `yaml:"name"`
  52. Timezone string `yaml:"timezone"`
  53. }
  54. type redis struct {
  55. Host string `yaml:"host"`
  56. Password string `yaml:"password"`
  57. }
  58. type logger struct {
  59. Switch int `yaml:"switch"`
  60. Path string `yaml:"path"`
  61. Name string `yaml:"name"`
  62. Level string `yaml:"level"`
  63. DbShowLog int `yaml:"db_show_log"`
  64. }
  65. type minio struct {
  66. Endpoint string `yaml:"endpoint"`
  67. Link string `yaml:"link"`
  68. AccessKey string `yaml:"access_key"`
  69. SecretKey string `yaml:"secret_key"`
  70. }
  71. type foreign struct {
  72. IotEdgeUrl string `yaml:"iot_edge_url"`
  73. IpCastEdgeUrl string `yaml:"ip_cast_edge_url"`
  74. SecurityRewindUrl string `yaml:"security_rewind_url"`
  75. }
  76. type email struct {
  77. Host string `yaml:"host"`
  78. Port string `yaml:"port"`
  79. AuthName string `yaml:"Auth-name"`
  80. PassWord string `yaml:"pass-word"`
  81. }
  82. type tencent struct {
  83. AppID string `yaml:"app_id"`
  84. SecretID string `yaml:"secret_id"`
  85. SecretKey string `yaml:"secret_key"`
  86. SmsKey string `yaml:"sms_key"`
  87. WarnSmsTemplateID string `yaml:"warn_sms_template_id"`
  88. }
  89. type sms struct {
  90. Tencent tencent `yaml:"tencent"`
  91. }
  92. type monitNotice struct {
  93. Email email `yaml:"email"`
  94. Sms sms `yaml:"sms"`
  95. }
  96. type es struct {
  97. URL string `yaml:"es_url"`
  98. }