介绍micro
使用go-micro简易搭建一个服务端
- 安装并运行consul,consul是一个服务发现软件。micro依赖于服务发现机制
安装:
Consul is the default registry/discovery for go-micro apps. It's however pluggable.
运行:
consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
micro web
- 启动server
进入目录 server/test
go run main.go
- 启动client
进入目录 client
go run main.go
可以看到 输出内容 证明client连接正常
- postman 测试
可以在 micro web页面 打开检查 然后在network下面拿到 刚刚的rpc 连接 然后 copy as curl
如下:
curl 'http://localhost:8082/rpc' -H 'Pragma: no-cache' -H 'Origin: http://localhost:8082' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' -H 'Content-type: application/json' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Referer: http://localhost:8082/query' -H 'Connection: keep-alive' --data-binary '{"service":"mymicro","method":"TestUser.GetUser","request":{}}' --compressed