Sam*_*uel 8 go swagger go-swagger
我是新手go-lang
,所以go-swagger
。我正在关注博客go-swagger
并 使用命令安装:
go get -u github.com/go-swagger/go-swagger/cmd/swagger
Run Code Online (Sandbox Code Playgroud)
我可以看到该go-swagger
文件夹是在
C:\Go\bin\src\github.com\go-swagger
Run Code Online (Sandbox Code Playgroud)
现在,我将项目路径添加到$GOPATH
:
echo %GOPATH%
C:\Go\bin;D:\Personal\Learning\GoLang\Project-2;D:\Personal\Learning\GoLang\swagger;
Run Code Online (Sandbox Code Playgroud)
当我跑步时
D:\Personal\Learning\GoLang\swagger>swagger ./swagger.yaml
'swagger' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
我缺少什么?另外,如果您能为我推荐一些好的材料,我将不胜感激,因为go-swagger
我发现设置所有内容都非常困难。没有太多博客可以帮助我进行HELLO WORLD
一些设置
谢谢
更新1:
我尝试设置GOBIN
但没有成功:
D:\Personal\Learning\GoLang\swagger>swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json
'swagger' is not recognized as an internal or external command,
operable program or batch file.
D:\Personal\Learning\GoLang\swagger>echo %GOBIN%
C:\Go\bin\;
Run Code Online (Sandbox Code Playgroud)
更新2:
我也按照建议尝试了绝对路径,但没有运气:
D:\Personal\Learning\GoLang\swagger>C:\Go\bin\swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json
'C:\Go\bin\swagger' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
更新3:
下面的命令对我有用,但它似乎不是正确的方法:
go run C:\Go\bin\src\github.com\go-swagger\go-swagger\cmd\swagger\swagger.go validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json
Run Code Online (Sandbox Code Playgroud)
错误应该是这样的。
您应该将%GOBIN%
目录添加到路径中。
修复:将此行添加到~/.zshrc
export PATH=$PATH:$HOME/go/bin
Run Code Online (Sandbox Code Playgroud)
注意:我的 go bin 文件夹位于$HOME/go/bin
如果不是您使用自定义路径的情况下。
完成上述更改后重新启动终端
当您安装 swagger 或任何其他 Go 二进制文件时,可执行文件位于该%GOBIN%
目录中。要调用swagger
可执行文件,您需要将%GOBIN%
目录添加到而Windows Path
不是GOPATH
使用绝对路径来调用它。
D:\Personal\Learning\GoLang\swagger> C:\Go\bin\swagger ./swagger.yaml
Run Code Online (Sandbox Code Playgroud)
要将 go 二进制文件添加到路径,请查看此处/sf/answers/668244181/。