gs.go 454 B

123456789101112131415161718192021222324252627282930
  1. package gs
  2. import (
  3. "gogs.tyduyong.com/duyong/dy-admin/internal/iam/config"
  4. "gorm.io/gorm"
  5. "sync"
  6. )
  7. // GlobalSource 服务依赖的外部通用资源
  8. type GlobalSource struct {
  9. PGSqlDB *gorm.DB
  10. MYSqlDB *gorm.DB
  11. }
  12. var (
  13. GS *GlobalSource
  14. once = sync.Once{}
  15. )
  16. func InitGS(config *config.Config) {
  17. // 初始化
  18. once.Do(func() {
  19. gs := &GlobalSource{}
  20. // pgsql
  21. pgDB := InitPGSqlDB(config.PGSQLOptions)
  22. gs.PGSqlDB = pgDB
  23. GS = gs
  24. })
  25. }