0

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)
4

0 回答 0