app.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package global
  2. import (
  3. "designs/utils"
  4. "github.com/go-redis/redis/v8"
  5. "github.com/robfig/cron/v3"
  6. "go.mongodb.org/mongo-driver/v2/mongo"
  7. "go.uber.org/zap"
  8. "gorm.io/gorm"
  9. "io"
  10. )
  11. type InitConfig struct {
  12. //InitDBFunc func() *gorm.DB
  13. InitRedisFunc func() *redis.Client
  14. }
  15. var Init = new(InitConfig)
  16. type Application struct {
  17. //配置
  18. //数据库
  19. DB *utils.WtDB
  20. //clickhouse
  21. Clickhouse *gorm.DB
  22. Redis *redis.Client
  23. Cron *cron.Cron
  24. //Machinery *machinery.Server
  25. //日志
  26. Log *zap.SugaredLogger
  27. LogWriter io.Writer
  28. MongoDB *mongo.Client
  29. PwdPath string
  30. }
  31. var (
  32. // DB *utils.WtDB
  33. // Redis *redis.Client
  34. Log *zap.SugaredLogger
  35. )
  36. var App = new(Application)
  37. func InitFacade() {
  38. // DB = App.DB
  39. // Redis = App.Redis
  40. Log = App.Log
  41. }
  42. //func DB() *utils.WtDB {
  43. // if App.DB != nil {
  44. // return App.DB
  45. // }
  46. //
  47. // App.DB = &utils.WtDB{DB: Init.InitDBFunc()}
  48. // return App.DB
  49. //}
  50. func Redis() *redis.Client {
  51. if App.Redis != nil {
  52. return App.Redis
  53. }
  54. App.Redis = Init.InitRedisFunc()
  55. return App.Redis
  56. }