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

问题描述

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

我想改用 go-swagger 版本 0.25。用 0.25 替换 dev 的干净方法是什么?

解决方法

安装过程与 master (dev) 版本相同,只是您需要再做一个额外的步骤,即在将 repo 克隆到临时目录后签出标签 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 中看到作者是如何做到这一点的。最终,您还可以添加其他标志以获得静态构建(但官方从源代码安装 说明中没有这样做)。

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

$ swagger version
version: v0.25.0
commit: f032690aab0634d97e2861a708d8fd9365ba77d2