3

我是新手go-lang,等等go-swagger。我正在关注一个博客go-swagger 使用命令安装:

go get -u github.com/go-swagger/go-swagger/cmd/swagger

我可以看到该go-swagger文件夹​​是在

C:\Go\bin\src\github.com\go-swagger

现在,我将我的项目路径添加到$GOPATH

echo %GOPATH%
C:\Go\bin;D:\Personal\Learning\GoLang\Project-2;D:\Personal\Learning\GoLang\swagger;

当我跑

D:\Personal\Learning\GoLang\swagger>swagger ./swagger.yaml
'swagger' is not recognized as an internal or external command,
operable program or batch file.

我错过了什么?另外,如果您能建议我一些好的材料,我将不胜感激,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\;

更新 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.

更新 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
4

3 回答 3

0

有预构建的二进制文件,您只需下载到任何文件夹,将文件夹添加到系统 PATH 即可从任何位置执行。在windows上,可以下载https://github.com/go-swagger/go-swagger/releases/download/v0.27.0/swagger_windows_amd64.exe(重命名二进制为swagger.exe,保存到C:\Users{你的用户}\go\bin)

于 2021-08-16T07:33:20.177 回答
0

当您go get somepackage/cmd/somecmd添加可执行文件时,不是添加到%GOBIN%,而是添加到%GOPATH%/bin.

因此,您必须将此目录添加到您的路径中:

echo %GOPATH%
// make sure you have a nonempty GOPATH
setx PATH %PATH%;%GOPATH%/bin
于 2021-01-08T15:49:30.370 回答
0

当您安装 swagger 或任何其他 Go 二进制文件时,可执行文件位于%GOBIN%目录中。要调用swagger可执行文件,您需要将%GOBIN%目录添加到Windows PathnotGOPATH或使用绝对路径调用它。

D:\Personal\Learning\GoLang\swagger> C:\Go\bin\swagger ./swagger.yaml

要将 go 二进制文件添加到路径中,请查看此处https://stackoverflow.com/a/9546345/1199408

于 2019-06-02T12:49:48.673 回答