第一次设置 go-swagger

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)

Anj*_*tam 5

针对 Mac 用户的修复

错误应该是这样的。

在此输入图像描述

您应该将%GOBIN%目录添加到路径中。

修复:将此行添加到~/.zshrc

export PATH=$PATH:$HOME/go/bin
Run Code Online (Sandbox Code Playgroud)

注意:我的 go bin 文件夹位于$HOME/go/bin如果不是您使用自定义路径的情况下。

完成上述更改后重新启动终端


geo*_*eok 1

当您安装 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/