forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.go
72 lines (54 loc) · 1.55 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package controller
import (
"bytes"
"database/sql"
"net/http"
"github.com/plumk97/go-admin/context"
"github.com/plumk97/go-admin/plugins/admin/modules/response"
)
// ShowInstall show install page.
func (h *Handler) ShowInstall(ctx *context.Context) {
buffer := new(bytes.Buffer)
//template.GetInstallPage(buffer)
//rs, _ := mysql.Query("show tables;")
//fmt.Println(rs[0]["Tables_in_godmin"])
//rs2, _ := mysql.Query("show columns from users")
//fmt.Println(rs2[0]["Field"])
ctx.HTML(http.StatusOK, buffer.String())
}
// CheckDatabase check the database connection.
func (h *Handler) CheckDatabase(ctx *context.Context) {
ip := ctx.FormValue("h")
port := ctx.FormValue("po")
username := ctx.FormValue("u")
password := ctx.FormValue("pa")
databaseName := ctx.FormValue("db")
SqlDB, err := sql.Open("mysql", username+":"+password+"@tcp("+ip+":"+port+")/"+databaseName+"?charset=utf8mb4")
if SqlDB != nil {
if SqlDB.Ping() != nil {
response.Error(ctx, "请检查参数是否设置正确")
return
}
}
defer func() {
_ = SqlDB.Close()
}()
if err != nil {
response.Error(ctx, "请检查参数是否设置正确")
return
}
//db.InitDB(username, password, port, ip, databaseName, 100, 100)
tables := make([]map[string]interface{}, 0)
list := "["
for i := 0; i < len(tables); i++ {
if i != len(tables)-1 {
list += `"` + tables[i]["Tables_in_godmin"].(string) + `",`
} else {
list += `"` + tables[i]["Tables_in_godmin"].(string) + `"`
}
}
list += "]"
response.OkWithData(ctx, map[string]interface{}{
"list": list,
})
}