Skip to content

Commit

Permalink
改用其他配置
Browse files Browse the repository at this point in the history
  • Loading branch information
fesiong committed Dec 22, 2020
1 parent cb8e767 commit bd64954
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 19 deletions.
5 changes: 2 additions & 3 deletions app/handler/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ func InstallForm(ctx iris.Context) {

mysqlUrl := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local",
req.User, req.Password, req.Host, req.Port, req.Database, config.MySQLConfig.Charset)
db, err := gorm.Open("mysql", mysqlUrl)
_, err := gorm.Open("mysql", mysqlUrl)
if err != nil {
ctx.JSON(iris.Map{
"code": config.StatusFailed,
"msg": err.Error(),
})
return
}
db.AutoMigrate(&core.Article{}, &core.ArticleData{}, &core.ArticleSource{})

config.JsonData.MySQL.Database = req.Database
config.JsonData.MySQL.User = req.User
config.JsonData.MySQL.Password = req.Password
config.JsonData.MySQL.Host = req.Host
config.JsonData.MySQL.Port = req.Port
config.JsonData.MySQL.TablePrefix = req.TablePrefix
config.JsonData.MySQL.Url = mysqlUrl
err = config.WriteConfig()
if err != nil {
Expand All @@ -63,6 +61,7 @@ func InstallForm(ctx iris.Context) {

config.InitJSON()
services.InitDB()
services.DB.AutoMigrate(&core.Article{}, &core.ArticleData{}, &core.ArticleSource{})

ctx.JSON(iris.Map{
"code": config.StatusOK,
Expand Down
1 change: 0 additions & 1 deletion app/request/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ type Install struct {
Host string `form:"host" validate:"required"`
Port int `form:"port" validate:"required"`
Charset string `form:"charset"`
TablePrefix string `form:"table_prefix" validate:"required"`
}
1 change: 0 additions & 1 deletion config.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"host": "localhost",
"port": 3306,
"charset": "utf8mb4",
"table_prefix": "fe_",
"max_idle_connections": 1000,
"max_open_connections": 100000
},
Expand Down
1 change: 0 additions & 1 deletion config/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type mySQLConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Charset string `json:"charset"`
TablePrefix string `json:"table_prefix"`
MaxIdleConnections int `json:"max_idle_connections"`
MaxOpenConnections int `json:"max_open_connections"`
Url string `json:"-"`
Expand Down
7 changes: 0 additions & 7 deletions services/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ func InitDB() {
//禁用复数表名
db.SingularTable(true)

//统一加前缀
if config.MySQLConfig.TablePrefix != "" {
gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
return config.MySQLConfig.TablePrefix + defaultTableName
}
}

DB = db
}
}
Expand Down
6 changes: 0 additions & 6 deletions template/install/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ <h1>初始化采集工具</h1>
<input type="text" name="password" required lay-verify="required" placeholder="填写数据库密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">表前缀</label>
<div class="layui-input-block">
<input type="text" name="table_prefix" required lay-verify="required" placeholder="默认是fe_" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit lay-filter="install">确认初始化</button>
Expand Down

0 comments on commit bd64954

Please sign in to comment.