twin-api/base/global/global.go

61 lines
1.2 KiB
Go

package global
import (
"os"
GsConfig "git.u8t.cn/open/go-server/config"
GsGlobal "git.u8t.cn/open/go-server/global"
"git.u8t.cn/open/gosdk/unify"
"github.com/gin-gonic/gin"
"github.com/go-co-op/gocron"
"github.com/go-redis/redis"
"github.com/mattn/go-colorable"
"github.com/olivere/elastic/v7"
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
)
func Init() {
if os.Getenv("CONFIG_ENV") == "rzh" || os.Getenv("CONFIG_ENV") == "rzh-test" || os.Getenv("CONFIG_ENV") == "dev" {
log.SetFormatter(&LogFile{
TextFormatter: log.TextFormatter{
ForceColors: true,
},
})
log.SetOutput(colorable.NewColorableStdout())
}
}
func GetConfig() *GsConfig.Config {
return GsConfig.GetConfig()
}
func GetDB() *gorm.DB {
return GsGlobal.GetDB()
}
func GetES() *elastic.Client {
return GsGlobal.GetES()
}
func GetRedis() *redis.Client {
return GsGlobal.GetRedis()
}
func GetGin() *gin.Engine {
return GsGlobal.GetGin()
}
func GetCron() *gocron.Scheduler {
return GsGlobal.GetCron()
}
func GetMessage() *unify.Message {
return GsGlobal.GetMessage()
}
func GetUnifyMessage(sender string) *unify.Message {
unifyConfig := GsConfig.GetConfig().Unify
return unify.NewMessage(unifyConfig.Address, unifyConfig.AdminToken, sender)
}