增加导入数据库命令

pull/30/head
taoshihan1991 4 years ago
parent b5975790a9
commit b271e8c4ba

@ -0,0 +1,37 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools"
"io/ioutil"
"os"
"strings"
)
var installCmd = &cobra.Command{
Use: "install",
Short: "example:go-fly install",
Run: func(cmd *cobra.Command, args []string) {
install()
},
}
func install(){
sqlFile:=config.Dir+"go-fly.sql"
isExit,_:=tools.IsFileExist(config.MysqlConf)
dataExit,_:=tools.IsFileExist(sqlFile)
if !isExit||!dataExit{
fmt.Println("config/mysql.json 数据库配置文件或者数据库文件go-fly.sql不存在")
os.Exit(1)
}
sqls,_:=ioutil.ReadFile(sqlFile)
sqlArr:=strings.Split(string(sqls),";")
for _,sql:=range sqlArr{
if sql==""{
continue
}
models.Execute(sql)
}
}

@ -30,4 +30,5 @@ func Execute() {
func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(installCmd)
}

@ -8,7 +8,7 @@ import (
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of go-fly",
Short: "example:go-fly version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("go-fly "+config.Version)
},

@ -22,6 +22,9 @@ func init(){
DB.DB().SetMaxIdleConns(10)
DB.DB().SetMaxOpenConns(100)
}
func Execute(sql string){
DB.Exec(sql)
}
func CloseDB() {
defer DB.Close()
}

@ -65,6 +65,8 @@
4. 源码打包 go build go-fly.go
5. 导入数据库(会删除表清空数据) go run go-fly.go install
### nginx部署
访问https://gofly.sopans.com

Loading…
Cancel
Save