2024-11-06 01:06:38 +08:00

63 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package variable
import (
"catface/app/global/my_errors"
"catface/app/utils/snow_flake/snowflake_interf"
"catface/app/utils/yml_config/ymlconfig_interf"
"log"
"os"
"strings"
"github.com/casbin/casbin/v2"
"github.com/yankeguo/zhipu"
"go.uber.org/zap"
"gorm.io/gorm"
)
var (
BasePath string // 定义项目的根目录
EventDestroyPrefix = "Destroy_" // 程序退出时需要销毁的事件前缀
ConfigKeyPrefix = "Config_" // 配置文件键值缓存时,键的前缀
DateFormat = "2006-01-02 15:04:05" // 设置全局日期时间格式
// INFO 全局日志指针
ZapLog *zap.Logger
// 全局配置文件
ConfigYml ymlconfig_interf.YmlConfigInterf // 全局配置文件指针
ConfigGormv2Yml ymlconfig_interf.YmlConfigInterf // 全局配置文件指针
//gorm 数据库客户端如果您操作数据库使用的是gorm请取消以下注释在 bootstrap>init 文件,进行初始化即可使用
GormDbMysql *gorm.DB // 全局gorm的客户端连接
GormDbSqlserver *gorm.DB // 全局gorm的客户端连接
GormDbPostgreSql *gorm.DB // 全局gorm的客户端连接
//雪花算法全局变量
SnowFlake snowflake_interf.InterfaceSnowFlake
//websocket
WebsocketHub interface{}
WebsocketHandshakeSuccess = `{"code":200,"msg":"ws连接成功","data":""}`
WebsocketServerPingMsg = "Server->Ping->Client"
//casbin 全局操作指针
Enforcer *casbin.SyncedEnforcer
// GLM 全局客户端
GlmClient *zhipu.Client
)
func init() {
// 1.初始化程序根目录
if curPath, err := os.Getwd(); err == nil {
// 路径进行处理,兼容单元测试程序程序启动时的奇怪路径
if len(os.Args) > 1 && strings.HasPrefix(os.Args[1], "-test") {
BasePath = strings.Replace(strings.Replace(curPath, `\test`, "", 1), `/test`, "", 1)
} else {
BasePath = curPath
}
} else {
log.Fatal(my_errors.ErrorsBasePath)
}
}