成功发布文章后,我收到了这条奇怪的消息。
[GIN] 2017/07/18 - 08:43:21 | 200 | 42.729836ms | 127.0.0.1 | POST /api/articles
signal: killed
我使用 curl 发布的帖子是:
curl -X POST http://127.0.0.1:8080/api/articles -v --cookie "domain=somelongstring" -F 'title=My title' -F 'content=Some stuff comes here' -F "file=@/home/me/Desktop/random.jpg" -H "Content-Type: multipart/form-data"
卷曲响应是这样的:
> Content-Length: 84289
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------47d5c18e46bf271a
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Tue, 18 Jul 2017 06:43:21 GMT
< Content-Length: 28
<
* Connection #0 to host 127.0.0.1 left intact
后处理程序是这样的:
func PostArticle(c *gin.Context) {
var err error
userId, userName := getUserId(c)
form, err := c.MultipartForm()
title := c.PostForm("title")
content := c.PostForm("content")
if err != nil {
fmt.Printf("%+v, %+v\n", form, err)
return
}
file, err := c.FormFile("file")
if err != nil {
log.Println(err)
c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
return
}
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
return
}
filename := path.Join(shared.RandString(6) + path.Ext(file.Filename))
dest := dir + "/static/photos/" + filename
if err := c.SaveUploadedFile(file, dest); err != nil {
c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
return
}
_, err = shared.Dbmap.Exec("INSERT INTO article (user_id, username, title, content, photo) VALUES (?, ?, ?, ?, ?)", userId, userName, title, content, filename)
if err != nil {
log.Fatal(err)
return
}
c.JSON(http.StatusOK, gin.H{"success": "article is created"})
}
我看到帖子已创建并且没有错误。在任何 GET 请求之后我也没有得到这个signal: killed
,所以想知道这里可能出了什么问题以及如何解决它?