goswagger generate swagger.yaml 生成swagger.yaml文件。

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

goswagger generate swagger.yaml

问题

我正在尝试为Go生成swagger.yaml文件。这是goswagger文档的链接:https://goswagger.io/install.html

我尝试了以下步骤:

docker pull quay.io/goswagger/swagger

alias swagger='docker run --rm -it  --user $(id -u):$(id -g) -e GOPATH=$(go env GOPATH):/go -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger'
swagger version

版本:v0.29.0 提交:53696caa1e8a4e5b483c87895d54eda202beb3b0

我尝试了export GOCACHE=$HOME/Library/Caches/go-buildexport GOCACHE=offexport GOCACHE=/tmp/
export GOCACHE=$HOME/.cache/go-build

但是当我运行以下命令时:

swagger generate spec -o ./swagger.yaml

我总是得到以下错误:

错误:退出状态 1:stderr:无法在/.cache/go-build初始化构建缓存:mkdir /.cache: 权限被拒绝

如果我正确理解错误的话,它似乎试图将文件写入根目录而不是我的主目录。这是我的go env变量:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/micahkimel/Library/Caches/go-build"
GOENV="/Users/micahkimel/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/micahkimel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/micahkimel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/micahkimel/go/src/GoDir/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4d/4xnmhr0j0478jh_6btr0nds80000gn/T/go-build1145095409=/tmp/go-build -gno-record-gcc-switches -fno-common"

感谢任何帮助!

英文:

I'm trying to generate swagger.yaml for go. Here is the link to the goswagger documentation https://goswagger.io/install.html

I tried the following:

docker pull quay.io/goswagger/swagger

alias swagger='docker run --rm -it  --user $(id -u):$(id -g) -e GOPATH=$(go env GOPATH):/go -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger'
swagger version

> version: v0.29.0 commit: 53696caa1e8a4e5b483c87895d54eda202beb3b0

I've tried export GOCACHE=$HOME/Library/Caches/go-build, export GOCACHE=off, export GOCACHE=/tmp/,
export GOCACHE=$HOME/.cache/go-build

but when I run

swagger generate spec -o ./swagger.yaml

I always get the following error

> err: exit status 1: stderr: failed to initialize build cache at
> /.cache/go-build: mkdir /.cache: permission denied

If I'm reading the error right it seems to be trying to write to the root directory instead of my home directory. Here are my go env vars

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/micahkimel/Library/Caches/go-build"
GOENV="/Users/micahkimel/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/micahkimel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/micahkimel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/micahkimel/go/src/GoDir/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4d/4xnmhr0j0478jh_6btr0nds80000gn/T/go-build1145095409=/tmp/go-build -gno-record-gcc-switches -fno-common"

Thanks for any help!!

答案1

得分: 0

我在这里的 GitHub 问题中找到了答案:https://github.com/go-swagger/go-swagger/issues/2633

我只需要在 Docker 别名中设置 GOCACHE

alias swagger='docker run --rm -it --user $(id -u):$(id -g) -e GOCACHE=/tmp -e GOPATH=$(go env GOPATH):/go -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger'
英文:

I found the answer in the github issues here https://github.com/go-swagger/go-swagger/issues/2633

I just needed to set the GOCACHE in the docker alias

alias swagger='docker run --rm -it  --user $(id -u):$(id -g) -e GOCACHE=/tmp -e  GOPATH=$(go env GOPATH):/go -v $HOME:$HOME -w $(pwd) quay.io/goswagger/swagger'

huangapple
  • 本文由 发表于 2022年7月22日 23:38:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/73082860.html
匿名

发表评论

匿名网友

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

确定