【问题标题】:Setting up go-swagger for first time第一次设置 go-swagger
【发布时间】:2019-10-18 05:12:38
【问题描述】:

我是go-langgo-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

【问题讨论】:

  • 嗨,这个问题你解决了吗?

标签: go swagger go-swagger


【解决方案1】:

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

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
【解决方案2】:

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

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

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • 绝对路径不走运: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..
    猜你喜欢
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多