-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths.go
63 lines (54 loc) · 1.29 KB
/
s.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
/*
* @Date: 2021-07-16 17:20:08
* @LastEditors: jaxiu
* @LastEditTime: 2021-08-11 10:31:53
* @FilePath: /test/gin/s.go
*/
package main
import (
"flag"
"fmt"
"net/http"
"path"
"github.com/gin-gonic/gin"
)
var Domain = flag.String("d",
"up.jaxiu.cn",
"-d your service domain.",
)
var Host = flag.String(
"h",
"0.0.0.0:8081",
"-h your hosts ip and port",
)
func main() {
flag.Parse()
r := gin.Default()
fmt.Println(gin.Version)
r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"Status": "服务运行中",
"Usage": "下载客户端: \nwin客户端 http://" + *Domain + "/download/client.exe\nLinux客户端 http://" + *Domain + "/download/client.linux\nMac客户端 http://" + *Domain + "/download/client.mac\n客户端的使用方式:./client* -h ",
})
})
r.Static("/download", "./upload")
r.POST("/up", s)
r.Run(*Host)
return
}
func s(c *gin.Context) {
fmt.Printf("Req: %+v\n", c.Request)
f, err := c.FormFile("file")
if err != nil {
fmt.Println("啥也不是", err)
c.JSON(502, err)
return
}
//将文件保存至本项目根目录中
c.SaveUploadedFile(f, path.Join("upload", f.Filename))
//保存成功返回正确的Json数据
c.JSON(http.StatusOK, gin.H{
"message": "OK",
"downurl": "http://" + *Domain + "/download/" + f.Filename,
})
}