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!!
CodePudding user response:
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'