在窗户上安装swaggo(swagger + gin)

时间:2018-05-20 14:59:50

标签: windows go swagger gin

我正试图在窗户上为gin-gonic设置招摇。 关于swaggo的文件陈述我应该运行:

go get -u github.com/swaggo/swag/cmd/swag

安装完成后,我应该可以在项目的根目录swag init内运行main.go,但cmdlet会说明以下内容:

swag : The term 'swag' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is    correct and try again.
At line:1 char:1
+ swag
+ ~~~~
+ CategoryInfo          : ObjectNotFound: (swag:String) [],  CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

如何添加swag到PATH或我应该如何从这里开始?

Ps,我关注了here

的文档

更新:所以我在另一台PC上进行了干净的Go安装,然后{j}右边的go get -u github.com/swaggo/swag/cmd/swagswag。之前我跟着this教程,我可能不小心弄乱了原来PC上的$GOPATH

2 个答案:

答案 0 :(得分:0)

将$ GOPATH / bin添加到PATH,例如:

export PATH = $ PATH:/ Users /.../ go / bin

答案 1 :(得分:0)

首先清除缓存

-go clean --modcache

如何在Go中安装swagger

-https://libraries.io/go/github.com%2Fswaggo%2Fhttp-swagger

-转到您的文件路径,他们安装以下软件包 1-go get github.com/swaggo/http-swagger 2-使用以下方式下载Swag for Go:

-go get github.com/swaggo/swag/cmd/swag

3-在包含main.go文件的Go项目根文件夹中运行Swag,Swag将解析注释并生成所需文件(docs文件夹和docs / doc.go)。

-swag init

4。使用以下方法下载http-swagger:

- go get -u github.com/swaggo/http-swagger

5-运行它,然后浏览器 -http://localhost:1323/swagger/index.html,您可以看到Swagger 2.0 Api文档。

要了解您正在处理的路径

-go env

然后查找GOPATH=,您将在其中看到自己的路径