我对golang相当陌生,在创建一个新模块时遇到了一些问题
我想在我的主包中添加一个git子模块,这样我就可以同时对两个包进行提交。
模块http_fs
作为git子模块添加,如下所示
git submodule add git@github.com:xxx/http_fs.git repo/http_fs
主包
package main
import "repo/http_fs"
go.mod
for http_fs
模块如下所示
module github.com/xxx/http_fs
go 1.19
当我尝试使用go run main.go
运行主包时,我会得到以下错误
package repo/http_fs is not in GOROOT (/usr/local/go/src/repo/http_fs)
文件结构
./main.go // main package
./repo/http_fs/http_fs.go
更新
主包中的go.mod
module main
go 1.19
replace github.com/xxx/http_fs v1 => ./repo/http_fs
发布于 2022-10-23 23:39:58
错误的原因
package repo/http_fs is not in GOROOT (/usr/local/go/src/repo/http_fs)
是go.mod
在/usr/local/go/src/repo/http_fs
中声明模块github.com/xxx/http_fs
,而不是repo/http_fs
。
您需要导入与go.mod
中指定的完全相同的模块,即github.com/xxx/http_fs
在主模块的go.mod
中,使用replace
指令:
replace github.com/xxx/http_fs v1.2.3 => ./repo/http_fs
where指令告诉编译器在哪里可以找到模块的源。
https://stackoverflow.com/questions/74174098
复制相似问题