diff --git a/README.md b/README.md index a79f3d0a..80e14b16 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ vi ./config/setting.yml ### 初始化数据库,以及服务启动 ``` # 首次配置需要初始化数据库资源信息 -./go-admin migrate -c config/settings.yml -m dev +./go-admin init -c config/settings.yml -m dev # 启动项目,也可以用IDE进行调试 diff --git a/cmd/api/server.go b/cmd/api/server.go index 0e48da24..aacbe891 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -10,6 +10,7 @@ import ( "go-admin/router" "go-admin/tools" config2 "go-admin/tools/config" + "io/ioutil" "log" "net/http" "os" @@ -76,7 +77,11 @@ func run() error { log.Fatalf("listen: %s\n", err) } }() - log.Println("Server Run ", config2.ApplicationConfig.Host+":"+config2.ApplicationConfig.Port) + content, _ := ioutil.ReadFile("./static/go-admin.txt") + log.Println(string(content)) + log.Println("Server Run http://127.0.0.1:"+config2.ApplicationConfig.Port+"/") + log.Println("Swagger URL http://127.0.0.1:"+config2.ApplicationConfig.Port+"/swagger/index.html") + log.Println("Enter Control + C Shutdown Server") // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) quit := make(chan os.Signal) diff --git a/cmd/migrate/server.go b/cmd/migrate/server.go index 897fb800..ac5968e8 100644 --- a/cmd/migrate/server.go +++ b/cmd/migrate/server.go @@ -6,7 +6,6 @@ import ( orm "go-admin/database" "go-admin/models" "go-admin/models/gorm" - tools2 "go-admin/models/tools" "go-admin/tools" config2 "go-admin/tools/config" "log" @@ -18,8 +17,8 @@ var ( config string mode string StartCmd = &cobra.Command{ - Use: "migrate", - Short: "migrate from struct to database", + Use: "init", + Short: "initialize the database", Run: func(cmd *cobra.Command, args []string) { run() }, @@ -32,7 +31,7 @@ func init() { } func run() { - usage := `start migrate` + usage := `start init` fmt.Println(usage) //1. 读取配置 config2.ConfigSetup(config) @@ -41,7 +40,7 @@ func run() { //3. 初始化数据库链接 database.Setup() //4. 数据库迁移 - _ = gorm.AutoMigrate(orm.Eloquent) + _ = migrateModel() log.Println("数据库结构初始化成功!") //5. 数据初始化完成 if err := models.InitDb(); err != nil { @@ -56,22 +55,5 @@ func migrateModel() error { if config2.DatabaseConfig.Dbtype == "mysql" { orm.Eloquent = orm.Eloquent.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4") } - orm.Eloquent.SingularTable(true) - return orm.Eloquent.AutoMigrate( - new(models.CasbinRule), - new(tools2.SysTables), - new(tools2.SysColumns), - new(models.Dept), - new(models.Menu), - new(models.LoginLog), - new(models.SysOperLog), - new(models.RoleMenu), - new(models.SysRoleDept), - new(models.SysUser), - new(models.SysRole), - new(models.Post), - new(models.DictData), - new(models.SysConfig), - new(models.DictType), - ).Error + return gorm.AutoMigrate(orm.Eloquent) } diff --git a/models/gorm/gorm.go b/models/gorm/gorm.go index d0b3da39..50c878f2 100644 --- a/models/gorm/gorm.go +++ b/models/gorm/gorm.go @@ -4,13 +4,9 @@ import ( "github.com/jinzhu/gorm" "go-admin/models" "go-admin/models/tools" - config2 "go-admin/tools/config" ) func AutoMigrate(db *gorm.DB) error { - if config2.DatabaseConfig.Dbtype == "mysql" { - db = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4") - } db.SingularTable(true) return db.AutoMigrate( new(models.CasbinRule), diff --git a/static/go-admin.txt b/static/go-admin.txt new file mode 100644 index 00000000..2353fcaf --- /dev/null +++ b/static/go-admin.txt @@ -0,0 +1,15 @@ + + ____ + ,---, ,' , `. ,--, + ,---. ,---,. ,---.'| ,-+-,.' _ |,--.'| ,---, + ,----._,. ' ,'\ ,' .' | | | : ,-+-. ; , ||| |, ,-+-. / | + / / ' / / / |,---.' , ,--.--. | | | ,--.'|' | ||`--'_ ,--.'|' | +| : |. ; ,. :| | |/ \ ,--.__| || | ,', | |,,' ,'| | | ,"' | +| | .\ .' | |: :: : .'.--. .-. | / ,' || | / | |--' ' | | | | / | | +. ; '; |' | .; :: |.' \__\/: . .. ' / || : | | , | | : | | | | | +' . . || : |`---' ," .--.; |' ; |: || : | |/ ' : |__ | | | |/ + `---`-'| | \ \ / / / ,. || | '/ '| | |`-' | | '.'|| | |--' + .'__/\_: | `----' ; : .' \ : :|| ;/ ; : ;| |/ + | : : | , .-./\ \ / '---' | , / '---' + \ \ / `--`---' `----' ---`-' + `--`-'