-
Notifications
You must be signed in to change notification settings - Fork 0
/
dionysus.go
43 lines (36 loc) · 998 Bytes
/
dionysus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Code generated by hertz generator.
package api
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
"github.com/cloudwego/kitex/client"
"github.com/supermicah/dionysus/api/biz/model/greet"
greetrpc "github.com/supermicah/dionysus/rpc/kitex_gen/greet"
dionysusrpc "github.com/supermicah/dionysus/rpc/kitex_gen/rpc/dionysus"
)
// Greet .
// @router greet [GET]
func Greet(ctx context.Context, c *app.RequestContext) {
var err error
var req greet.GreetRequest
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
// Use kitex client to make rpc calls and request back-end services
cli, err := dionysusrpc.NewClient("rpc", client.WithHostPorts("127.0.0.1:8888"))
if err != nil {
panic(err)
}
respRpc, err := cli.Greet(ctx, &greetrpc.GreetRequest{
Greet: "21",
Name: "22",
Gender: "23",
})
if err != nil {
panic(err)
}
c.JSON(consts.StatusOK, respRpc)
}