首次设置摇摆

时间:2019-06-02 09:51:20

标签: go swagger go-swagger

我是go-lang的新手,go-swagger也是如此。我正在关注a blog,并使用以下命令安装了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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

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

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

echo %GOPATH%
// make sure you have a nonempty GOPATH
setx PATH %PATH%;%GOPATH%/bin