dongshao8125 2017-07-24 14:49
浏览 14

信号:在功能结束时被杀死

Using go-gin I have this function to receive posted jokes and saved them to database:

func PostJoke(c *gin.Context) {
    var err error

    userId, userName, userAvatar := shared.GetUserInfo(c)

    if userId == 0 {
        c.JSON(403, gin.H{"error": "not authorized"})
    }

    title := c.PostForm("title")
    content := c.PostForm("content")
    nsfwSt := c.PostForm("nsfw")
    nsfw, err := strconv.Atoi(nsfwSt)
    if err != nil {
        log.Panic(err)
        c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
    }

    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)
    }
    filename := path.Join(shared.RandString(6) + path.Ext(file.Filename))
    dest := dir + "/media/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 joke (user_id, username, user_avatar, title, content, photo, nsfw) VALUES (?, ?, ?, ?, ?, ?, ?)", userId, userName, userAvatar, title, content, filename, nsfw)
    if err != nil {
        log.Println(err)
        c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
    }

    fmt.Println("end of function")
    c.JSON(http.StatusOK, gin.H{"sccess": "joke is created"})

}

The function works as expected: saves the data and returns "sccess": "joke is created" However at the end I receive this mysterious error at the terminal:

signal: killed

and does not respond anymore.

I'm wondering what can cause this and how to fix it?

UPDATE: go version go1.8.3 linux/amd64

and here is my go env:

me@pc:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/me/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build842411537=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

When I try to rebuild all packages using sudo go install -a , I get:

main.go:8:2: cannot find package "github.com/gin-gonic/contrib/sessions" in any of:
    /usr/lib/go-1.6/src/github.com/gin-gonic/contrib/sessions (from $GOROOT)
    ($GOPATH not set)
main.go:9:2: cannot find package "github.com/gin-gonic/gin" in any of:
    /usr/lib/go-1.6/src/github.com/gin-gonic/gin (from $GOROOT)
    ($GOPATH not set)
main.go:4:2: cannot find package "proj/controller" in any of:
    /usr/lib/go-1.6/src/proj/controller (from $GOROOT)
    ($GOPATH not set)
main.go:5:2: cannot find package "proj/middleware" in any of:
    /usr/lib/go-1.6/src/proj/middleware (from $GOROOT)
    ($GOPATH not set)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表