This repository was archived by the owner on Feb 2, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ # RPC API
2+
3+ 使用Stack Gateway插件暴露RPC服务
4+
5+ ### 运行RPC,参考[ RPC-Demo] ( ../../service/rpc )
6+
7+ ``` bash
8+ go run server.go
9+ ```
10+
11+ ### 运行Gateway
12+
13+ 运行本示例中的main.go
14+
15+ ``` bash
16+ go run main.go
17+ ```
18+
19+ ### 请求
20+
21+ ``` bash
22+ curl POST ' 127.0.0.1:8080/greeter/hello' \
23+ --header ' Content-Type: application/json' \
24+ --data-raw ' {
25+ "name": "Curl Client"
26+ }'
27+ ```
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "github.com/stack-labs/stack-rpc"
5+ "github.com/stack-labs/stack-rpc-plugins/service/gateway"
6+ "github.com/stack-labs/stack-rpc/util/log"
7+ )
8+
9+ func main () {
10+ svc := stack .NewService (stack .Name ("stack.rpc" ))
11+ gateway .Hook (svc )
12+
13+ // run service
14+ if err := svc .Run (); err != nil {
15+ log .Fatal (err )
16+ }
17+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ replace (
77 github.com/stack-labs/stack-rpc v1.0.0 => ../../stack-rpc
88 github.com/stack-labs/stack-rpc-plugins/config/source/apollo v1.0.0 => ../../stack-rpc-plugins/config/source/apollo
99 github.com/stack-labs/stack-rpc-plugins/logger/logrus v1.0.0 => ../../stack-rpc-plugins/logger/logrus
10+ github.com/stack-labs/stack-rpc-plugins/service/gateway v1.0.0 => ../../stack-rpc-plugins/service/gateway
1011 google.golang.org/grpc => google.golang.org/grpc v1.26.0
1112)
1213
@@ -46,6 +47,7 @@ require (
4647 github.com/micro/go-plugins/micro/cors/v2 v2.3.0
4748 github.com/micro/go-plugins/registry/consul v0.0.0-20200119172437-4fe21aa238fd
4849 github.com/micro/go-plugins/registry/etcdv3 v0.0.0-20200119172437-4fe21aa238fd
50+ github.com/stack-labs/stack-rpc-plugins/service/gateway v1.0.0
4951 github.com/micro/micro/v2 v2.3.1
5052 github.com/nats-io/jwt v1.1.0 // indirect
5153 github.com/nats-io/nats.go v1.10.0 // indirect
You can’t perform that action at this time.
0 commit comments