Skip to content

Commit

Permalink
自定义mysql链接添加数据库名输入
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Apr 11, 2020
1 parent 3c283ba commit 97f526f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ type Mysql struct {
Enabled bool `json:"enabled"`
ServerAddr string `json:"server_addr"`
ServerPort int `json:"server_port"`
Database string `json:"db"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
Cafile string `json:"cafile"`
}

// User 用户表记录结构体
Expand Down
1 change: 0 additions & 1 deletion core/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func GetMysql() *Mysql {
// WriterMysql 写mysql配置
func WriterMysql(mysql *Mysql) bool {
mysql.Enabled = true
mysql.Database = "trojan"
config := Load("")
config.Mysql = *mysql
return Save(config, "")
Expand Down
4 changes: 2 additions & 2 deletions trojan/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ func InstallMysql() {
mysql.Password = util.Input(fmt.Sprintf("请输入mysql %s用户的密码: ", mysql.Username), "")
db := mysql.GetDB()
if db != nil && db.Ping() == nil {
db.Exec("CREATE DATABASE IF NOT EXISTS trojan;")
mysql.Database = util.Input("请输入使用的数据库名(不存在可自动创建, 回车使用trojan): ", "trojan")
db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s;", mysql.Database))
break
} else {
fmt.Println("连接mysql失败, 请重新输入")
}
}
}
mysql.Database = "trojan"
mysql.CreateTable()
core.WriterMysql(&mysql)
if len(mysql.GetData()) == 0 {
Expand Down

0 comments on commit 97f526f

Please sign in to comment.