【问题标题】:Replace go-swagger with another version in Windows在 Windows 中用另一个版本替换 go-swagger
【发布时间】:2021-01-07 03:24:27
【问题描述】:

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

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

【问题讨论】:

    标签: go go-swagger


    【解决方案1】:

    安装过程与 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。版本信息只是从 git 存储库作为commands 包中的变量内容传递下来的装饰性信息,您可以在他们的 CircleCI 配置文件here 中看到作者是如何做到的。最终,您还可以添加其他标志来获得静态构建(但官方从源代码安装说明中没有这样做)。

    完成后,您应该在 $GOPATH/bin 中安装 go-swagger v0.25.0,通过以下方式验证:

    $ swagger version
    version: v0.25.0
    commit: f032690aab0634d97e2861a708d8fd9365ba77d2
    

    【讨论】:

    • +1 用于指出如何为源安装获取正确的版本信息。之前遇到过麻烦,如果这是某处文档的一部分,那就太好了。
    猜你喜欢
    • 2018-06-18
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    相关资源
    最近更新 更多