micro的安装

micro的安装

下载micro

$ go get -u -v github.com/go-log/log
$ go get -u -v github.com/gorilla/handlers 
$ go get -u -v github.com/gorilla/mux
$ go get -u -v github.com/gorilla/websocket
$ go get -u -v github.com/mitchellh/hashstructure
$ go get -u -v github.com/nlopes/slack
$ go get -u -v github.com/pborman/uuid
$ go get -u -v github.com/pkg/errors
$ go get -u -v github.com/serenize/snaker
# hashicorp_consul.zip包解压在github.com/hashicorp/consul
$ unzip hashicorp_consul.zip -d github.com/hashicorp/consul
# miekg_dns.zip 包解压在github.com/miekg/dns
$ unzip miekg_dns.zip -d github.com/miekg/dns
$ go get github.com/micro/micro@v1.18.0

编译安装micro

go 用的是1.13,高版本会有问题。

$ cd $GOPATH/src/github.com/micro/micro
$ go build   -o micro  main.go 
$ sudo cp micro /bin/

插件安装

go get -u -v github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u -v github.com/micro/protoc-gen-micro

关于github下载慢的问题

vim /etc/hosts
192.30.253.112 github.com
151.101.185.194 github.global.ssl.fastly.net
reboot




[root@localhost wj]# micro new --type "srv" micro/rpc/srv
Creating service go.micro.srv.srv in /home/gopath/src/micro/rpc/srv

.
├── main.go
├── generate.go
├── plugin.go
├── handler
│   └── srv.go
├── subscriber
│   └── srv.go
├── proto/srv
│   └── srv.proto
├── Dockerfile
├── Makefile
├── README.md
└── go.mod


download protobuf for micro:

brew install protobuf
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u github.com/micro/protoc-gen-micro

compile the proto file srv.proto:

cd /home/gopath/src/micro/rpc/srv
protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. proto/srv/srv.proto

[root@localhost wj]#

[root@localhost srv]# protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. proto/srv/srv.proto
[root@localhost srv]# ls
Dockerfile go.mod main.go plugin.go README.md srv.pb.micro.go
generate.go handler Makefile proto srv.pb.go subscriber
[root@localhost srv]#

 

 

[root@localhost src]# micro new --type "web" micro/rpc/web
Creating service go.micro.web.web in /home/gopath/src/micro/rpc/web

.
├── main.go
├── plugin.go
├── handler
│   └── handler.go
├── html
│   └── index.html
├── Dockerfile
├── Makefile
├── README.md
└── go.mod

 

#编译后将web端呼叫srv端的客户端连接内容修改为srv的内容
#需要进行调通

 

 

 

 
posted @ 2022-02-22 17:03  b02330224  阅读(193)  评论(0编辑  收藏  举报