-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_db.go
56 lines (49 loc) · 1.09 KB
/
web_db.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
package main
import (
"net/http"
"github.com/gin-gonic/gin"
log "github.com/tengfei-xy/go-log"
)
func dbTableGETRequest(c *gin.Context) {
r, err := dbTableGET()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
}
c.String(http.StatusOK, r)
}
func dbTableDeleteRequest(c *gin.Context) {
err := dbTableDelete()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
var res resStruct
c.JSON(http.StatusOK, res.setOK("已删除"))
}
func dbTablePUTRequest(c *gin.Context) {
var res resStruct
// 读取文件
file, err := c.FormFile("file")
if err != nil {
log.Error(err)
c.JSON(http.StatusOK, res.setErrSystem())
return
}
// 保存文件
err = c.SaveUploadedFile(file, "upload.sql")
if err != nil {
log.Error(err)
c.String(http.StatusOK, res.setErrSystem().toString())
return
}
if err := dbReset("upload.sql"); err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
r, err := dbTableGET()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
c.String(http.StatusOK, r)
}