gpt4 book ai didi

go - 修复 go 使用的工具版本

转载 作者:数据小太阳 更新时间:2023-10-29 03:21:28 37 4
gpt4 key购买 nike

我希望使用 go 创建可重现的构建。对于个别项目,我们正在使用 glide。

例如我使用:

glide get github.com/stretchr/testify

修复“证明”包的版本。但是,这不适用于工具。例如:

glide install github.com/tebeka/go2xunit

返回成功但实际上并没有安装go2xunit所以我必须使用:

go get github.com/tebeka/go2xunit

go2xunit 安装到 $GOPATH/bin

Q如何修复go2xunit等工具的版本?

我还注意到 glide says use dep instead部门说 golang has diverged from its implementation并且可能最终会使用基于 vgo 的东西. go 有很多依赖管理工具,也许不太知名的工具之一支持这个?

如果相关,我使用的是 Debian9 提供的 go 1.7.4。

最佳答案

go1.11 使用go modules 的解决方案是创建一个fake tools package .您创建一个 tools.go 文件,如下所示:

// +build tools

package tools

import (
_ "github.com/tebeka/go2xunit"
)

+build tools 是一个神奇的注释,它会阻止构建包。

>go mod init tools

将为假的工具包创建一个go.mod文件

>go install github.com/tebeka/go2xunit

将安装 go2xunit 并更新 go.mod 如下。

module tools

require github.com/tebeka/go2xunit v1.4.8 // indirect

现在,如果您将来运行 go install github.com/tebeka/go2xunit(对于干净的构建而言),go.mod 会将其版本固定为 v1.4


对于 1.11 之前的 go 版本,要使用的工具是 retool .它是这样工作的:

自举:

go get github.com/twitchtv/retool

添加工具:

retool add github.com/jteeuwen/go-bindata/go-bindata origin/master

使用工具:

retool do go-bindata -pkg testdata -o ./testdata/testdata.go ./testdata/data.json

添加对此的支持可能在目标 go 1.12 ( https://github.com/golang/go/issues/27653 ) 的路线图上

关于go - 修复 go 使用的工具版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53086136/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com