Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 08d3399

Browse files
committed
增加网关示例
1 parent f16f38d commit 08d3399

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

examples/gateway/rpc/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
```

examples/gateway/rpc/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

examples/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)