You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/controller/mysql.go

47 lines
1012 B

package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/tools"
"os"
)
func MysqlGetConf(c *gin.Context) {
mysqlInfo:=config.GetMysql()
c.JSON(200, gin.H{
"code": 200,
"msg": "验证成功",
"result":mysqlInfo,
})
}
func MysqlSetConf(c *gin.Context) {
mysqlServer:=c.PostForm("server")
mysqlPort:=c.PostForm("port")
mysqlDb:=c.PostForm("database")
mysqlUsername:=c.PostForm("username")
mysqlPassword:=c.PostForm("password")
isExist, _ := tools.IsFileExist(config.Dir)
if !isExist {
os.Mkdir(config.Dir, os.ModePerm)
}
fileConfig := config.MysqlConf
file, _ := os.OpenFile(fileConfig, os.O_RDWR|os.O_CREATE, os.ModePerm)
format := `{
"Server":"%s",
"Port":"%s",
"Database":"%s",
"Username":"%s",
"Password":"%s"
}
`
data := fmt.Sprintf(format, mysqlServer,mysqlPort,mysqlDb,mysqlUsername,mysqlPassword)
file.WriteString(data)
c.JSON(200, gin.H{
"code": 200,
"msg": "操作成功",
})
}