3

I am new to go-lang and so to go-swagger. I am following a blog and have installed go-swagger with command :

go get -u github.com/go-swagger/go-swagger/cmd/swagger

I can see that the go-swagger folder is created in

C:\Go\bin\src\github.com\go-swagger

Now, I added my project path to $GOPATH :

echo %GOPATH%
C:\Go\bin;D:\Personal\Learning\GoLang\Project-2;D:\Personal\Learning\GoLang\swagger;

When I run

D:\Personal\Learning\GoLang\swagger>swagger ./swagger.yaml
'swagger' is not recognized as an internal or external command,
operable program or batch file.

What am I missing ? Also, I would be grateful if you can suggest me some good material for go-swagger as I am finding it very difficult to setup everything. There arent much blogs which can help me do HELLO WORLD kinda setup

Thanks

Update 1:

I tried to set GOBIN but no luck with that:

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\;

Update 2:

I tried absolute path as suggested as well, but no luck:

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.

Update 3:

Below command worked for me but it doesn't seem to be proper way:

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
Samuel
  • 682
  • 3
  • 11
  • 27

2 Answers2

0

When you install swagger or any other Go binary, the executable is on the %GOBIN% directory. To call the swagger executable you need to add the %GOBIN% directory to the Windows Path not the GOPATH or call it using the absolute path.

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

To add the go binaries to the path look here https://stackoverflow.com/a/9546345/1199408.

georgeok
  • 4,233
  • 2
  • 29
  • 50
  • No luck with absolute path : `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.` . – Samuel Jun 05 '19 at 06:52
0

When you do go get somepackage/cmd/somecmd the executable is added, not to %GOBIN%, but rather to %GOPATH%/bin.

You must therefore add this directory to your path:

echo %GOPATH%
// make sure you have a nonempty GOPATH
setx PATH %PATH%;%GOPATH%/bin
Ezequiel Muns
  • 5,919
  • 23
  • 45