go-micro的安装与使用
安装与应用
安装
Micro
# go get
$ go get github.com/micro/micro/v2
# docker install
$ docker pull microhq/micro
Go-Micro
Go Micro是Go开发微服务的RPC框架 (用2.x好了)
$ go get github.com/micro/go-micro/v2
protobuf
如果使用代码生成,您还需要使用protoc-gen-go
$ go get github.com/micro/protobuf/{
proto,protoc-gen-go}
gRPC 网关
protobuf
mkdir tmp
cd tmp
git clone https://github.com/google/protobuf
cd protobuf
./autogen.sh
./configure
make
make check
sudo make install
安装插件
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/micro/protobuf/protoc-gen-go
Micro 命令
创建服务
# 新建一个服务
$ micro new service-name
NAME:
micro new - Create a new micro service
USAGE:
micro new [command options] [arguments...]
OPTIONS:
--namespace "go.micro" Namespace for the service e.g com.example
--type "srv" Type of service e.g api, srv, web
--fqdn FQDN of service e.g com.example.srv.service (defaults to namespace.type.alias)
--alias Alias is the short name used as part of combined name if specified
启动、运行服务
# 在本地运行该服务并确保其正常工作.
# 启动服务器
micro server
# 设置为本地环境
micro