2

My code works fine on my computer but I get this compile-time error on my server after I moved the code to the Debian server:

type *gin.Context has no field or method SaveUploadedFile

I use sample gin code to save file:

    if err := c.SaveUploadedFile(file, file.Filename); err != nil {
        c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
        return
    }

I have upgraded go to 1.8.3 on the server (to be of the same version as go on my desktop) and updated gin afterwards, hoping to solve the issue. But it did not.

Here is my go env:

root@s1:~# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/srv/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"
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"

I have also tried:

rm -rf $GOPATH/pkg/*

I also tried go build -a, but get the same error.

4

1 回答 1

4

It seems your server is using old codebase of gin. Just checked the gin commit history.

The method SaveUploadedFile added 5 days ago. So execute below command to pull the latest codebase on your server.

go get -u github.com/gin-gonic/gin

Then compile it.

于 2017-07-21T02:00:22.177 回答