baseOptions.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package options
  2. import (
  3. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/database/myredis"
  4. "sync"
  5. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/app/server"
  6. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/database/myorm"
  7. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/log"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/objectStore"
  9. )
  10. type Options struct {
  11. Log *log.Options `json:"log"`
  12. Server *server.SeverOption `json:"server" mapstructure:"server"`
  13. DB *myorm.DBOption `json:"database" mapstructure:"database"`
  14. IpWhiteList []string `json:"ipWhiteList" mapstructure:"ipWhiteList"`
  15. Storage *objectStore.Options `json:"storage" mapstructure:"storage"`
  16. Nats *NatsOption `json:"nats" `
  17. BzdClod *BzdOption `json:"bzdClod" mapstructure:"bzdClod"`
  18. Wechat *WechatOption `json:"wechat" mapstructure:"wechat"`
  19. Redis *myredis.RedisOption `json:"redis"`
  20. }
  21. var (
  22. once sync.Once
  23. OptInstance *Options
  24. )
  25. func NewOptions() *Options {
  26. once.Do(func() {
  27. o := Options{
  28. Log: log.NewOptions(),
  29. }
  30. OptInstance = &o
  31. })
  32. return OptInstance
  33. }
  34. // Validate 统一验证...
  35. func (o *Options) Validate() []error {
  36. var errs []error
  37. errs = append(errs, o.Log.Validate()...)
  38. return errs
  39. }