diff --git a/cmd/api/server.go b/cmd/api/server.go index 93b938a..6dc6a19 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -10,7 +10,6 @@ import ( "ferry/tools" config2 "ferry/tools/config" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -100,10 +99,14 @@ func run() error { } } }() - content, _ := ioutil.ReadFile("./static/ferry.txt") - fmt.Println(string(content)) - fmt.Printf("%s Server Run http://127.0.0.1:%s/ \r\n", tools.GetCurrntTimeStr(), config2.ApplicationConfig.Port) - fmt.Printf("%s Swagger URL http://127.0.0.1:%s/swagger/index.html \r\n", tools.GetCurrntTimeStr(), config2.ApplicationConfig.Port) + fmt.Printf("%s Server Run http://%s:%s/ \r\n", + tools.GetCurrntTimeStr(), + config2.ApplicationConfig.Host, + config2.ApplicationConfig.Port) + fmt.Printf("%s Swagger URL http://%s:%s/swagger/index.html \r\n", + tools.GetCurrntTimeStr(), + config2.ApplicationConfig.Host, + config2.ApplicationConfig.Port) fmt.Printf("%s Enter Control + C Shutdown Server \r\n", tools.GetCurrntTimeStr()) // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) quit := make(chan os.Signal) diff --git a/config/db.sql b/config/db.sql index 114b600..9e12468 100644 --- a/config/db.sql +++ b/config/db.sql @@ -87,7 +87,7 @@ INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ( INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/deptTree', 'GET', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/logout', 'POST', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/user/avatar', 'POST', NULL, NULL, NULL); -INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/user/pwd', 'PUT', NULL, NULL, NULL; +INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/user/pwd', 'PUT', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'common', '/api/v1/dashboard', 'GET', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/api/v1/settings', 'POST', NULL, NULL, NULL); INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`) VALUES ('p', 'admin', '/api/v1/settings', 'GET', NULL, NULL, NULL); diff --git a/models/system/initdb.go b/models/system/initdb.go index 40134a1..d7bde60 100644 --- a/models/system/initdb.go +++ b/models/system/initdb.go @@ -24,13 +24,13 @@ func InitDb() error { return err } sqlList := strings.Split(sql, ";") - for i := 0; i < len(sqlList)-1; i++ { - if strings.Contains(sqlList[i], "--") { - fmt.Println(sqlList[i]) + for _, sql := range sqlList { + if strings.Contains(sql, "--") { + fmt.Println(sql) continue } - sql := strings.Replace(sqlList[i]+";", "\n", "", 0) - if err = orm.Eloquent.Exec(sql).Error; err != nil { + sqlValue := strings.Replace(sql+";", "\n", "", 1) + if err = orm.Eloquent.Exec(sqlValue).Error; err != nil { if !strings.Contains(err.Error(), "Query was empty") { return err } @@ -43,7 +43,6 @@ func Ioutil(name string) (string, error) { if contents, err := ioutil.ReadFile(name); err == nil { //因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符 result := strings.Replace(string(contents), "\n", "", 1) - fmt.Println("Use ioutil.ReadFile to read a file:", result) return result, nil } else { return "", err