swag :术语“swag”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称

nev*_*dhf 1 powershell command-line swagger

我的问题是,当我尝试运行时,swag init我看到以下内容

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 init
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (swag:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

我尝试了 stackoverflow 上的所有指南,但没有任何帮助以你能想象到的方式改变我的环境变量,没有任何帮助。

我的 GOPATH 设置为 %USERPROFILE%\go,这是我从官方网站安装 go 的文件夹。我的 Path 变量有 %USERPROFILE%\go\bin。

当我尝试go generate为 golang/mock 库运行另一个命令时,我也遇到同样的错误。

请帮助我)如果需要,我将提供任何屏幕截图/信息

小智 9

如果上述解决方案不起作用,请尝试像这样安装 swag

go install github.com/swaggo/swag/cmd/swag@latest
Run Code Online (Sandbox Code Playgroud)

参考这个 - https://github.com/swaggo/swag


小智 8

您需要添加添加$GOPATH/bin到$PATH. 在 Linux 中,可以将以下内容添加到 bash 配置文件中:

export PATH=$PATH:$(go env GOPATH)/bin
Run Code Online (Sandbox Code Playgroud)