go解决引入私有包报错“Repository owner does not exist“的两种方式
当你写好引入的私有包,执行go mod tidy报错:
Gogs: Repository owner does not exist
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
目前我的两种解决方案:
一、拉群整个包的代码,然后简单粗暴的replace为本项目的同名包目录
module basego 1.22require (git.imooc.com/coding-535/common v0.0.0-20220913123407-af94ee6eb5c3github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5github.com/asim/go-micro/plugins/registry/consul/v3 v3.7.0github.com/asim/go-micro/plugins/wrapper/ratelimiter/uber/v3 v3.7.0github.com/asim/go-micro/plugins/wrapper/trace/opentracing/v3 v3.7.0github.com/asim/go-micro/v3 v3.7.0github.com/jinzhu/gorm v1.9.16github.com/opentracing/opentracing-go v1.2.0google.golang.org/protobuf v1.27.1k8s.io/api v0.22.4 //其它版本会报错k8s.io/client-go v0.22.4 //其它版本会报错
)
replace git.imooc.com/coding-535/common v0.0.0-20220913123407-af94ee6eb5c3 => ../common
二、修改GOPRIVATE和git的全局配置
修改go env的GOPRIVATE配置:
go env -w GOPRIVATE=git.imooc.com
注:其他env配置就略过了,本文只写了适合主题的配置。
修改git的全局配置:
git config --global url."git@git.imooc.com:".insteadof https://git.imooc.com/
然后测试,使用go mod tidy 验证:
user模块的go.mod
module git.imooc.com/coding-535/usergo 1.22require (git.imooc.com/coding-535/common v0.0.0-20220913123407-af94ee6eb5c3github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5github.com/asim/go-micro/plugins/registry/consul/v3 v3.7.0github.com/asim/go-micro/plugins/wrapper/ratelimiter/uber/v3 v3.7.0github.com/asim/go-micro/plugins/wrapper/trace/opentracing/v3 v3.7.0github.com/asim/go-micro/v3 v3.7.0github.com/jinzhu/gorm v1.9.16github.com/opentracing/opentracing-go v1.2.0google.golang.org/protobuf v1.27.1k8s.io/api v0.22.4 //其它版本会报错k8s.io/client-go v0.22.4 //其它版本会报错
)require (github.com/Microsoft/go-winio v0.5.0 // indirectgithub.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirectgithub.com/acomagu/bufpipe v1.0.3 // indirectgithub.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirectgithub.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirectgithub.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirectgithub.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirectgithub.com/asim/go-micro/plugins/config/source/consul/v3 v3.0.0-20210904061721-270d910b7328 // indirectgithub.com/beorn7/perks v1.0.1 // indirectgithub.com/bitly/go-simplejson v0.5.0 // indirectgithub.com/cpuguy83/go-md2man/v2 v2.0.0 // indirectgithub.com/davecgh/go-spew v1.1.1 // indirectgithub.com/emirpasic/gods v1.12.0 // indirectgithub.com/fatih/color v1.9.0 // indirectgithub.com/fsnotify/fsnotify v1.4.9 // indirectgithub.com/go-git/gcfg v1.5.0 // indirectgithub.com/go-git/go-billy/v5 v5.3.1 // indirectgithub.com/go-git/go-git/v5 v5.4.2 // indirectgithub.com/go-logr/logr v0.4.0 // indirectgithub.com/go-sql-driver/mysql v1.5.0 // indirectgithub.com/gogo/protobuf v1.3.2 // indirectgithub.com/golang/protobuf v1.5.2 // indirectgithub.com/google/go-cmp v0.5.6 // indirectgithub.com/google/gofuzz v1.1.0 // indirectgithub.com/google/uuid v1.2.0 // indirectgithub.com/googleapis/gnostic v0.5.5 // indirectgithub.com/hashicorp/consul/api v1.9.0 // indirectgithub.com/hashicorp/go-cleanhttp v0.5.1 // indirectgithub.com/hashicorp/go-hclog v0.12.0 // indirectgithub.com/hashicorp/go-immutable-radix v1.0.0 // indirectgithub.com/hashicorp/go-rootcerts v1.0.2 // indirectgithub.com/hashicorp/golang-lru v0.5.1 // indirectgithub.com/hashicorp/serf v0.9.5 // indirectgithub.com/imdario/mergo v0.3.12 // indirectgithub.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirectgithub.com/jinzhu/inflection v1.0.0 // indirectgithub.com/json-iterator/go v1.1.11 // indirectgithub.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirectgithub.com/mattn/go-colorable v0.1.8 // indirectgithub.com/mattn/go-isatty v0.0.12 // indirectgithub.com/matttproud/golang_protobuf_extensions v1.0.1 // indirectgithub.com/miekg/dns v1.1.43 // indirectgithub.com/mitchellh/go-homedir v1.1.0 // indirectgithub.com/mitchellh/hashstructure v1.1.0 // indirectgithub.com/mitchellh/mapstructure v1.3.3 // indirectgithub.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirectgithub.com/modern-go/reflect2 v1.0.1 // indirectgithub.com/nxadm/tail v1.4.8 // indirectgithub.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirectgithub.com/patrickmn/go-cache v2.1.0+incompatible // indirectgithub.com/pkg/errors v0.9.1 // indirectgithub.com/prometheus/client_golang v1.1.0 // indirectgithub.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirectgithub.com/prometheus/common v0.6.0 // indirectgithub.com/prometheus/procfs v0.0.3 // indirectgithub.com/russross/blackfriday/v2 v2.0.1 // indirectgithub.com/sergi/go-diff v1.1.0 // indirectgithub.com/shurcooL/sanitized_anchor_name v1.0.0 // indirectgithub.com/sirupsen/logrus v1.7.0 // indirectgithub.com/spf13/pflag v1.0.5 // indirectgithub.com/uber/jaeger-client-go v2.29.1+incompatible // indirectgithub.com/uber/jaeger-lib v2.4.1+incompatible // indirectgithub.com/urfave/cli/v2 v2.3.0 // indirectgithub.com/xanzy/ssh-agent v0.3.0 // indirectgo.uber.org/atomic v1.7.0 // indirectgo.uber.org/multierr v1.1.0 // indirectgo.uber.org/ratelimit v0.2.0 // indirectgo.uber.org/zap v1.10.0 // indirectgolang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirectgolang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirectgolang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirectgolang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirectgolang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirectgolang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirectgolang.org/x/text v0.3.6 // indirectgolang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirectgoogle.golang.org/appengine v1.6.5 // indirectgopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirectgopkg.in/inf.v0 v0.9.1 // indirectgopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirectgopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirectgopkg.in/warnings.v0 v0.1.2 // indirectgopkg.in/yaml.v2 v2.4.0 // indirectgopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirectk8s.io/apimachinery v0.22.4 // indirectk8s.io/klog/v2 v2.9.0 // indirectk8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a // indirectsigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirectsigs.k8s.io/yaml v1.2.0 // indirect
)
验证结果:
PS D:\go-projects\git.imooc.com\coding-535\user> go mod tidy
go: downloading git.imooc.com/coding-535/common v0.0.0-20220913123407-af94ee6eb5c3
PS D:\go-projects\git.imooc.com\coding-535\user>
goland的代码是绿色的,就表明成功了!