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

icomxhvb  于 2022-11-06  发布在  Go
关注(0)|答案(3)|浏览(157)

我正在尝试在windows上为gin-gonic设置swagger。swaggo的文档说明我应该运行:

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

安装后,我应该能够从项目的根目录(其中有main.go)运行swag init,但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的干净安装,然后立即运行了go get -u github.com/swaggo/swag/cmd/swagswag。早些时候,我按照this教程进行了操作,我可能不小心在原来的PC上搞砸了我的$GOPATH

kg7wmglp

kg7wmglp1#

将$GOPATH/bin添加到PATH中,例如:
导出路径=$PATH:/用户/.../go/bin

lnvxswe2

lnvxswe22#

按照下面的文章来获得杜松子酒的昂首阔步
https://levelup.gitconnected.com/tutorial-generate-swagger-specification-and-swaggerui-for-gin-go-web-framework-9f0c038483b5
如果你遇到任何问题,以获得赃物使用下面的命令来获得赃物的窗口

go install github.com/swaggo/swag/cmd/swag
8yoxcaq7

8yoxcaq73#

首先清空缓存

-go clean --modcache

如何安装swagger在围棋

-https://libraries.io/go/github.com%2Fswaggo%2Fhttp-swagger
  • 转到您的文件路径他们安装以下软件包1-go get github.com/swaggo/http-swagger 2-Download Swag for Go通过使用:
-go get github.com/swaggo/swag/cmd/swag

3-在你的Go项目根文件夹中运行Swag,它包含main.go文件,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=,在那里您将看到您路径

相关问题