baseInit.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package util
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/esv7"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. "app.yhyue.com/moapp/jyfs/rpc/filesystemclient"
  6. "github.com/tal-tech/go-zero/core/discov"
  7. "github.com/tal-tech/go-zero/zrpc"
  8. "gorm.io/gorm"
  9. "log"
  10. )
  11. type MysqlDBConfig struct {
  12. DriverName string
  13. DataSourceName string
  14. MaxOpenConn int
  15. MaxIdleConn int
  16. MaxConnLifeTime int
  17. }
  18. type EsConfig struct {
  19. Addr string
  20. Pool int
  21. UserName string
  22. Password string
  23. }
  24. var (
  25. jyDocsDB *gorm.DB
  26. FileSystem filesystemclient.FileSystem
  27. )
  28. func InitDB(url, driverName string, maxOpenConn, maxIdle int) {
  29. jyDocsDB = mysql.GormMysql(url, driverName, maxOpenConn, maxIdle, nil)
  30. if jyDocsDB != nil {
  31. log.Printf("----------->【jy_docs】 DB :[%s] 初始化成功!<--------------", url)
  32. } else {
  33. log.Fatalf("----------->【jy_docs】 DB初始化失败<--------------")
  34. }
  35. }
  36. func InitEs(addr string, poolSize int, userName, password string) {
  37. log.Printf("----------->【jy_docs】 elastic :[%s] init<--------------", addr)
  38. elastic.InitElasticSizeByAuth(addr, poolSize, userName, password)
  39. }
  40. func InitOss(etcd discov.EtcdConf) {
  41. client := zrpc.MustNewClient(zrpc.RpcClientConf{
  42. Etcd: etcd,
  43. })
  44. FileSystem = filesystemclient.NewFileSystem(client)
  45. }
  46. func GetJyDocsDB() *gorm.DB {
  47. return jyDocsDB
  48. }