-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
63 lines (50 loc) · 1.03 KB
/
controller.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func uploadFunc(c *gin.Context) {
file, _ := c.FormFile("file")
log.Println(file.Filename)
dst := "static/uploadfile/" + file.Filename
// 上传文件到指定的路径
c.SaveUploadedFile(file, dst)
c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
}
func uploadMultipartFunc(c *gin.Context) {
form, _ := c.MultipartForm()
files := form.File["files[]"]
for _, file := range files {
log.Println(file.Filename)
dst := "static/uploadfile/" + file.Filename
c.SaveUploadedFile(file, dst)
}
c.String(http.StatusOK, "Uploaded...")
}
func getFunc(c *gin.Context) {
c.JSON(200, gin.H{
"message": "GET",
})
}
func postFunc(c *gin.Context) {
c.JSON(200, gin.H{
"message": "POST",
})
}
func patchFunc(c *gin.Context) {
c.JSON(200, gin.H{
"message": "PATCH",
})
}
func putFunc(c *gin.Context) {
c.JSON(200, gin.H{
"message": "PUT",
})
}
func deleteFunc(c *gin.Context) {
c.JSON(200, gin.H{
"message": "DELETE",
})
}