Golang中如何导入本地模块而不重新下载其依赖项?
Golang中如何导入本地模块而不重新下载其依赖项?
我有一个模块 sample_project,其 go.mod 文件如下:
module sample_project
go 1.21.6
replace local.mod/module_to_import => ../module_to_import
require (
github.com/ethereum/go-ethereum v1.13.11
...
)
但是 module_to_import 对 github.com/ethereum/go-ethereum 有一个替换,因为它使用了 ethereum-go 的 arbitrum 版本,该版本包含一些与 arbitrum 相关的内容(类型、函数等)。
以下是它的 go.mod 文件:
module module_to_import
go 1.21.6
replace github.com/ethereum/go-ethereum => ./go-ethereum
require (
...
)
现在,这是 sample_project 的 main.go 文件:
import (
...
imported_utils "local.mod/module_to_import/utils"
)
问题是,当执行 go run main.go 时,它会尝试下载 module_to_import 所需的所有包,并且我会收到类似这样的错误:
找到了模块
github.com/ethereum/go-ethereum@latest(v1.13.11),但不包含包github.com/ethereum/go-ethereum/arbitrum_types
我想使用位于 ../module_to_import/go-ethereum 的本地包。我该如何实现?
更多关于Golang中如何导入本地模块而不重新下载其依赖项?的实战教程也可以访问 https://www.itying.com/category-94-b0.html
我认为(但不确定)添加你自己的 go-ethereum 替换应该能解决问题。你试过这个方法吗?
更多关于Golang中如何导入本地模块而不重新下载其依赖项?的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


