config.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package config
  2. import (
  3. . "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mail"
  5. "gopkg.in/natefinch/lumberjack.v2"
  6. )
  7. // OSSAccount 表示OSS帐号信息
  8. type OSSAccount struct {
  9. ID string `json:"id"`
  10. Endpoint string `json:"endpoint"`
  11. AccessKeyId string `json:"access_key_id"`
  12. AccessKeySecret string `json:"access_key_secret"`
  13. }
  14. // BucketInfo 表示bucket维表数据
  15. type BucketInfo struct {
  16. BucketID string `json:"bucket_id"`
  17. AccountID string `json:"account_id"`
  18. BucketName string `json:"bucket_name"`
  19. }
  20. type PushMail struct {
  21. Addr string `json:"addr"`
  22. Port int `json:"port"`
  23. Pwd string `json:"pwd"`
  24. User string `json:"user"`
  25. MailPoolSize int `json:"mailPoolSize"`
  26. MailReTry int `json:"mailReTry"`
  27. }
  28. // Config 为全局配置结构体
  29. type Config struct {
  30. Port string `json:"port"`
  31. OSSAccounts []OSSAccount `json:"oss_accounts"`
  32. Buckets []BucketInfo `json:"buckets"`
  33. Node struct {
  34. NodeName string `json:"node_name"`
  35. } `json:"node"`
  36. Redis struct {
  37. Address string `json:"address"`
  38. Password string `json:"password"`
  39. } `json:"redis"`
  40. Email struct {
  41. Mails []*PushMail `json:"mails"`
  42. Title string `json:"title"`
  43. Recipients []string `json:"recipients"`
  44. } `json:"email"`
  45. Weixin struct {
  46. WebhookURL string `json:"webhook_url"`
  47. } `json:"weixin"`
  48. WarnMaxNodeNum int `json:"warnMaxNodeNum"`
  49. WarnInterval int64 `json:"warnInterval"`
  50. Logger *lumberjack.Logger `json:"logger"`
  51. }
  52. var (
  53. AppConfig Config
  54. Gmails []*mail.GmailAuth
  55. )
  56. // LoadConfig 从指定的配置文件中加载配置
  57. func init() {
  58. ReadConfig(&AppConfig)
  59. Gmails = make([]*mail.GmailAuth, len(AppConfig.Email.Mails))
  60. for k, v := range AppConfig.Email.Mails {
  61. Gmails[k] = &mail.GmailAuth{
  62. SmtpHost: v.Addr,
  63. SmtpPort: v.Port,
  64. User: v.User,
  65. Pwd: v.Pwd,
  66. PoolSize: v.MailPoolSize,
  67. ReTry: v.MailReTry,
  68. }
  69. }
  70. }