Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package zooKeeperMgr
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ZooKeeper配置对象
|
||||
type ZooKeeperConfig struct {
|
||||
// ZooKeeper的服务器地址(如果有多个地址,则用,分隔)
|
||||
Servers string
|
||||
|
||||
// 起始节点路径
|
||||
StartPath string
|
||||
|
||||
// 会话超时时间(单位:秒)
|
||||
SessionTimeout time.Duration
|
||||
}
|
||||
|
||||
// 获取所有的ZooKeeper服务器列表
|
||||
func (this *ZooKeeperConfig) GetServerList() []string {
|
||||
return strings.Split(this.Servers, ",")
|
||||
}
|
||||
|
||||
func (this *ZooKeeperConfig) Parse() {
|
||||
this.SessionTimeout = this.SessionTimeout * time.Second
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package connection
|
||||
|
||||
var (
|
||||
// 存放实体结构
|
||||
dbModelMap = make([]interface{}, 0)
|
||||
)
|
||||
|
||||
// RegisterDBModel 注册数据库模型到全局变量dbModelMap中。
|
||||
// 这个函数接受一个interface{}类型的参数dbModel,表示数据库模型。
|
||||
// 函数的目的是将传入的数据库模型添加到全局变量dbModelMap中,
|
||||
// 以便在其他地方可以访问和使用这些数据库模型。
|
||||
func RegisterDBModel(dbModel interface{}) {
|
||||
// 将dbModel的地址添加到dbModelMap中。
|
||||
// 这里使用地址是因为数据库模型可能比较大,通过引用存储可以提高效率。
|
||||
dbModelMap = append(dbModelMap, &dbModel)
|
||||
}
|
||||
|
||||
// BuildDB 用于遍历dbModelMap中的所有数据库模型,并检查每个模型对应的表是否存在于数据库中。
|
||||
// 如果表不存在,则自动迁移(创建)该表。这样可以确保数据库模式与程序中的模型保持同步。
|
||||
func BuildDB() {
|
||||
// 遍历dbModelMap中的每个元素
|
||||
for _, dbModel := range dbModelMap {
|
||||
|
||||
// 检查数据库中是否存在与dbModel对应的表
|
||||
tableExists := GetAdminDB().Migrator().HasTable(dbModel)
|
||||
if !tableExists {
|
||||
// 如果表不存在,则进行自动迁移
|
||||
GetAdminDB().AutoMigrate(dbModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/center.iml" filepath="$PROJECT_DIR$/.idea/center.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Reference in New Issue
Block a user