go微服务学习 go-micro框架

Posted Demonwuwen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go微服务学习 go-micro框架相关的知识,希望对你有一定的参考价值。

由于 Micro3.0直接放弃维护 go-micro,所以网上很多文章都是已经过时的了。那些安装方法根本装不上了。此贴主要根据官方文档进行摸索,感觉官方文档似乎也没来得及更新,所以部分操作也没能成功。就只记录一下自己成功的操作和遇到的问题。

依赖

我们需要protoc-gen-micro来生成代码
protobuf
protoc-gen-go
protoc-gen-micro

#Download latest proto releaes
#https://github.com/protocolbuffers/protobuf/releases
go get github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro

安装micro

使用go安装

go get -u -v github.com/micro/micro

go install github.com/micro/micro

这种安装可能会报错
错误1:
micro/util/acme/options.go:19:8: cannot find package "github.com/go-acme/lego/v3/challenge" in any of: /usr/local/go/src/github.com/go-acme/lego/v3/challenge (from $GOROOT) /Users/demon/StudyFile/go/src/github.com/go-acme/lego/v3/challenge (from $GOPATH) micro/service/api/server/server.go:9:2: cannot find package "github.com/go-acme/lego/v3/providers/dns/cloudflare" in any of: /usr/local/go/src/github.com/go-acme/lego/v3/providers/dns/cloudflare (from $GOROOT) /Users/demon/StudyFile/go/src/github.com/go-acme/lego/v3/providers/dns/cloudflare (from $GOPATH) ../xanzy/go-gitlab/gitlab.go:38:2: cannot find package "golang.org/x/oauth2" in any of: /usr/local/go/src/golang.org/x/oauth2 (from $GOROOT) /Users/demon/StudyFile/go/src/golang.org/x/oauth2 (from $GOPATH) ../../golang.org/x/crypto/ssh/terminal/terminal.go:14:2: cannot find package "golang.org/x/term" in any of: /usr/local/go/src/golang.org/x/term (from $GOROOT) /Users/demon/StudyFile/go/src/golang.org/x/term (from $GOPATH) ../xanzy/go-gitlab/gitlab.go:39:2: cannot find package "golang.org/x/time/rate" in any of: /usr/local/go/src/golang.org/x/time/rate (from $GOROOT) /Users/demon/StudyFile/go/src/golang.org/x/time/rate (from $GOPATH)
这是因为https://github.com/micro/micro里没有v3这个网页了,我们将micro/micro目录下的Makefile中的GIT_IMPORT=github.com/micro/micro/v3/cmd改为GIT_IMPORT=github.com/micro/micro/cmd即可正常执行。

如果遇到以下错误,则是由于protobuf版本不兼容导致。
#github.com/coreos/etcd/clientv3/balancer/resolver/endpoint ../../../../pkg/mod/github.com/coreos/etcd@v3.3.17+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:114:78: undefined: resolver.BuildOption ../../../../pkg/mod/github.com/coreos/etcd@v3.3.17+incompatible/clientv3/balancer/resolver/endpoint/endpoint.go:182:31: undefined: resolver.ResolveNowOption #github.com/coreos/etcd/clientv3/balancer/picker ../../../../pkg/mod/github.com/coreos/etcd@v3.3.17+incompatible/clientv3/balancer/picker/err.go:37:44: undefined: balancer.PickOptions ../../../../pkg/mod/github.com/coreos/etcd@v3.3.17+incompatible/clientv3/balancer/picker/roundrobin_balanced.go:55:54: undefined: balancer.PickOptions
解决办法:
打开go.mod文件,添加

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0

再重新执行即可。

docker镜像安装

docker pull micro/micro

这里坑太多了~,先踩踩,后面再更吧。😭

以上是关于go微服务学习 go-micro框架的主要内容,如果未能解决你的问题,请参考以下文章

go微服务学习 go-micro框架-—— micro安装

go微服务学习 go-micro框架-—— micro安装

go微服务学习 go-micro框架-—— micro安装

go微服务框架go-micro深度学习 整体架构介绍

go微服务框架go-micro深度学习 Registry服务的注册和发现

go微服务学习 go-micro框架