type *gin.Context没有SaveUploadedFile字段或方法。

huangapple go评论146阅读模式
英文:

type *gin.Context has no field or method SaveUploadedFile

问题

我的代码在我的电脑上运行正常,但是在将代码移动到Debian服务器后,我在编译时遇到了以下错误:

type *gin.Context has no field or method SaveUploadedFile

我使用了sample gin code来保存文件:

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

我已经将服务器上的go升级到1.8.3(与我的桌面上的go版本相同),然后更新了gin,希望能解决这个问题。但是没有成功。

这是我的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"

我还尝试过:

rm -rf $GOPATH/pkg/*

我还尝试了go build -a,但是得到了相同的错误。

英文:

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.

答案1

得分: 4

看起来你的服务器正在使用旧版本的gin代码库。我刚刚查看了gin的提交历史。

方法SaveUploadedFile5天前添加的。所以请在你的服务器上执行以下命令来获取最新的代码库。

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

然后进行编译。

英文:

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.

huangapple
  • 本文由 发表于 2017年7月21日 09:45:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/45227703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定