You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package variable
import (
"github.com/casbin/casbin/v2"
"go.uber.org/zap"
"gorm.io/gorm"
"goskeleton/app/global/my_errors"
"goskeleton/app/utils/snow_flake/snowflake_interf"
"goskeleton/app/utils/yml_config/ymlconfig_interf"
"log"
"os"
"strings"
)
// ginskeleton 封装的全局变量全部支持并发安全,请放心使用即可
// 开发者自行封装的全局变量,请做好并发安全检查与确认
var (
BasePath string // 定义项目的根目录
EventDestroyPrefix = "Destroy_" // 程序退出时需要销毁的事件前缀
ConfigKeyPrefix = "Config_" // 配置文件键值缓存时,键的前缀
DateFormat = "2006-01-02 15:04:05" // 设置全局日期时间格式
// 全局日志指针
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
// 用户自行定义其他全局变量 ↓
)
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)
}
}