package util import ( elastic "app.yhyue.com/moapp/jybase/esv7" "app.yhyue.com/moapp/jybase/mysql" "app.yhyue.com/moapp/jyfs/rpc/filesystemclient" "github.com/tal-tech/go-zero/core/discov" "github.com/tal-tech/go-zero/zrpc" "gorm.io/gorm" "log" ) type MysqlDBConfig struct { DriverName string DataSourceName string MaxOpenConn int MaxIdleConn int MaxConnLifeTime int } type EsConfig struct { Addr string Pool int UserName string Password string } var ( jyDocsDB *gorm.DB FileSystem filesystemclient.FileSystem ) func InitDB(url, driverName string, maxOpenConn, maxIdle int) { jyDocsDB = mysql.GormMysql(url, driverName, maxOpenConn, maxIdle, nil) if jyDocsDB != nil { log.Printf("----------->【jy_docs】 DB :[%s] 初始化成功!<--------------", url) } else { log.Fatalf("----------->【jy_docs】 DB初始化失败<--------------") } } func InitEs(addr string, poolSize int, userName, password string) { log.Printf("----------->【jy_docs】 elastic :[%s] init<--------------", addr) elastic.InitElasticSizeByAuth(addr, poolSize, userName, password) } func InitOss(etcd discov.EtcdConf) { client := zrpc.MustNewClient(zrpc.RpcClientConf{ Etcd: etcd, }) FileSystem = filesystemclient.NewFileSystem(client) } func GetJyDocsDB() *gorm.DB { return jyDocsDB }