1

I am using go1.14.1 and go-swagger version dev in my Windows 10. I installed go-swagger with Installing from source.

I'd like to use go-swagger version 0.25 instead. What is the clean way of replacing dev with 0.25?

Helen
  • 87,344
  • 17
  • 243
  • 314
AEWRocks
  • 157
  • 1
  • 2
  • 10

1 Answers1

1

The installation process is same as for master (dev) version except you need to do one more additional step which is checking out tag v0.25.0 after cloning the repo to temporary directory:

dir=$(mktemp -d) 
git clone https://github.com/go-swagger/go-swagger "$dir" 
cd "$dir"

# Checkout version v0.25.0
git checkout v0.25.0

# Continue with installation, instead of
# go install ./cmd/swagger

# use this which just adds version information (current tag) and commit id to binary
go install -ldflags "-X github.com/go-swagger/go-swagger/cmd/swagger/commands.Version=$(git describe --tags) -X github.com/go-swagger/go-swagger/cmd/swagger/commands.Commit=$(git rev-parse HEAD)" ./cmd/swagger

NOTE: If you do just go install ./cmd/swagger it will technically still install v0.25.0 but swagger version subcommand will report it as dev. The version information is just a cosmetic thing passed from git repository down as content of variables in commands package and you can see how authors do it in their CircleCI config file here. Eventually you can add also other flags to get static build (but they don't do that in official Installing from source instructions).

Once done you should have go-swagger v0.25.0 installed in your $GOPATH/bin, verify with:

$ swagger version
version: v0.25.0
commit: f032690aab0634d97e2861a708d8fd9365ba77d2
blami
  • 6,588
  • 2
  • 23
  • 31
  • +1 for pointing out how to get the version information correct for source installs. Had troubles with that before, would be nice if this was part of the doc somewhere. – Ezequiel Muns Jan 07 '21 at 11:34