用 Windows 中的另一个版本替换 go-swagger

Replace go-swagger with another version in Windows

我在 Windows 10 中使用 go1.14.1go-swagger 版本 dev。我用 Installing from source 安装了 go-swagger

我想使用 go-swagger 版本 0.25 instead. What is the clean way of replacing dev with 0.25?

安装过程与主 (dev) 版本相同,只是您需要再执行一个附加步骤,即在将存储库克隆到临时目录后检查标签 v0.25.0

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

注意:如果您只执行 go install ./cmd/swagger,它在技术上仍会安装 v0.25.0,但 swagger version 子命令会将其报告为 dev。版本信息只是作为 commands 包中的变量内容从 git 存储库传递下来的装饰性信息,您可以在他们的 CircleCI 配置文件 here 中看到作者是如何做到的。最终你还可以添加其他标志来获得静态构建(但他们不会在官方 Installing from source 说明中这样做)。

完成后,您应该在 $GOPATH/bin 中安装了 go-swagger v0.25.0,验证:

$ swagger version
version: v0.25.0
commit: f032690aab0634d97e2861a708d8fd9365ba77d2