forked from Meduoduo/kisara
/
main.go
61 lines (46 loc) · 1011 Bytes
/
main.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
package main
import (
"bytes"
"fmt"
"mime/multipart"
"time"
"github.com/Yeuoly/kisara/src/helper"
"github.com/gin-gonic/gin"
_ "embed"
)
//go:embed test.tar.gz
var tarfile []byte
type FileTransmission struct {
File *multipart.FileHeader `form:"file" binding:"required"`
}
func main() {
go func() {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.POST("/upload", func(c *gin.Context) {
var fileTransmission FileTransmission
c.ShouldBind(&fileTransmission)
fmt.Println(fileTransmission)
fmt.Println(fileTransmission.File)
c.JSON(200, gin.H{
"message": "ok",
})
})
r.Run(":7777")
}()
time.Sleep(time.Second * 1)
fmt.Println("Sending file...")
// read tarfile
reader := bytes.NewBuffer(tarfile)
resp, err := helper.SendPostAndParse[map[string]any](
"http://localhost:7777/upload",
helper.HttpPyloadMultipart(
map[string]string{},
helper.HttpPayloadMultipartFile("file", reader),
),
)
if err != nil {
panic(err)
}
fmt.Println(resp)
}