我正在编写一个Golang应用程序,并希望利用现有的库. 但是该库缺少一些功能,所以我决定派生repo并添加我的新功能.
为了能够在我的应用程序中使用派生/扩展库,我使用了Golang的"工作区"特性.
我的应用程序回购中的go.work
看起来像
go 1.21.4
use (
.
../go-git-cmd-wrapper // this is the local path to the forked/edited lib repo
)
只要我只在派生的lib中扩展现有的包,就可以很好地工作. 也就是说,一旦我开始在派生的库中创建一个新的包,我就会得到如下的构建错误:
我在forked/cloned lib go-git-cmd-wrapper/log/log.go
中添加了一个新的包,
package log
.... // my new functionality
例如,在我的应用程序中,我导入了库的现有包和新包
package main
import (
....
// the following three work as expected, i.e. I can add new functionality
// to those packages and use them in my application
gwbranch "github.com/ldez/go-git-cmd-wrapper/v2/branch"
gwconfig "github.com/ldez/go-git-cmd-wrapper/v2/config"
gw "github.com/ldez/go-git-cmd-wrapper/v2/git"
// the following doesn't work, I get import error on build
gwlog "github.com/ldez/go-git-cmd-wrapper/v2/log"
....
)
go: finding module for package github.com/ldez/go-git-cmd-wrapper/v2/log
go: changeme imports
github.com/ldez/go-git-cmd-wrapper/v2/log: module github.com/ldez/go-git-cmd-wrapper/v2@latest found (v2.6.0), but does not contain package github.com/ldez/go-git-cmd-wrapper/v2/log
exit status 1
我如何修复这样的错误?我在工作空间和/或分支库方面做错了什么?