golang 之 go-micro

Before installing first need to have some understanding of the go-micro

https://micro.mu/docs/cn/   Go Micro-Chinese documents

 

https://juejin.im/post/5cebafe6f265da1bb80c0cc7   Go Micro- source

 

https://segmentfault.com/a/1190000007917576   prodoful grammar

 micro

The following code execution period of time, etc., to the final findings do not complete the installation, do not worry, because some micro package is required FQ to download, use the following method one by one to install the missing

go get -u github.com/micro/micro

 protobuf

Can be used directly brew install protobuf write in, you can go git  https://github.com/protocolbuffers/protobuf/releases download the latest installation package can be downloaded and then compile. The following can be the final installation.

After unpacking the bin folder adding environment variables, adding or inside protoc.exe path environment variable, this is our exe file conversion protobuf tools.

Then we use some golang for protobuf tool, go get the appropriate library

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

consul

go-micro default consul, if you do not like to use the consul, also can download etcd or other installation, follow-up will explain how to install etcd.

Direct command to install or use to https://www.consul.io/downloads.html 

brew install consul

 After downloading adding environment variables, start

consul agent -dev

Installation grpc and genproto

mkdir $ GOPATH / src / google.golang.org 
cd $ GOPATH / src / google.golang.org 

git clone https://github.com/grpc/grpc-go.git grpc 
git clone https://github.com/ google / go-genproto.git genproto

Installation golang the net, crypt, text library

mkdir $ GOPATH / src / golang.org / x 
cd $ GOPATH / src / golang.org / x 

git clone https://github.com/golang/net.git 
git clone https://github.com/golang /crypto.git 
git clone https://github.com/golang/text.git

 The last execution in the Mac environment, without being given're done.

go install github.com/micro/micro

 Environment Variables

Whether windows, mac or Linux command you want to execute micro environment variables need to be configured.  

cd GOPATH/src/github.com/micro/micro

执行 go build

 Will generate GOPATH / bin folder micro.exe file, after GOPATH / bin folder path environment variable to join us to run directly micro command, and if there is no file in the bin folder to generate it manually move the folder.

test

Execute the following command to generate go-micro projects

micro new github.com/micro/example

 Note github.com/micro/example just an example, to test locally, directly into his path to the

Then the generated project in GOPATH / src / hdy / micro / example

example/
    Dockerfile  # A template docker file
    README.md   # A readme with command used
    handler/    # Example rpc handler
    main.go     # The main Go program
    proto/      # Protobuf directory
    subscriber/ # Example pubsub Subscriber

  Then run

protoc --proto_path=. --micro_out=. --go_out=. proto/example/example.proto

  Ensure etcd or consul before the final run is open state

go run main.go

  You can see the complete a project.

Detect

micro list services 
list all services

See also detailed GitHub   https://github.com/micro/micro

  

 

  

 

 

Guess you like

Origin www.cnblogs.com/flash55/p/11300627.html