-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_service.lug.pb.go
150 lines (144 loc) · 4.68 KB
/
echo_service.lug.pb.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Code generated by protoc-gen-lug. DO NOT EDIT.
// versions:
// - protoc-gen-lug v0.1.0
// - protoc v3.17.3
// source: proto/gid/echo_service.proto
package gid
import (
fiber "github.com/pubgo/lug/pkg/builder/fiber"
gutil "github.com/pubgo/lug/pkg/gutil"
grpcc "github.com/pubgo/lug/plugins/grpcc"
xgen "github.com/pubgo/lug/xgen"
byteutil "github.com/pubgo/x/byteutil"
xerror "github.com/pubgo/xerror"
grpc "google.golang.org/grpc"
reflect "reflect"
strings "strings"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
func GetEchoServiceClient(srv string, opts ...func(cfg *grpcc.Cfg)) func(func(cli EchoServiceClient)) error {
client := grpcc.GetClient(srv, opts...)
return func(fn func(cli EchoServiceClient)) (err error) {
defer xerror.RespErr(&err)
c, err := client.Get()
if err != nil {
return xerror.WrapF(err, "srv: %s", srv)
}
fn(&echoServiceClient{c})
return
}
}
func init() {
var mthList []xgen.GrpcRestHandler
mthList = append(mthList, xgen.GrpcRestHandler{
Input: &SimpleMessage{},
Output: &SimpleMessage{},
Service: "gid.EchoService",
Name: "Echo",
Method: "POST",
Path: "/v1/example/echo/{id}",
DefaultUrl: false,
ClientStream: false,
ServerStream: false,
})
mthList = append(mthList, xgen.GrpcRestHandler{
Input: &SimpleMessage{},
Output: &SimpleMessage{},
Service: "gid.EchoService",
Name: "EchoBody",
Method: "POST",
Path: "/v1/example/echo_body",
DefaultUrl: false,
ClientStream: false,
ServerStream: false,
})
mthList = append(mthList, xgen.GrpcRestHandler{
Input: &SimpleMessage{},
Output: &SimpleMessage{},
Service: "gid.EchoService",
Name: "EchoDelete",
Method: "DELETE",
Path: "/v1/example/echo_delete",
DefaultUrl: false,
ClientStream: false,
ServerStream: false,
})
mthList = append(mthList, xgen.GrpcRestHandler{
Input: &DynamicMessageUpdate{},
Output: &DynamicMessageUpdate{},
Service: "gid.EchoService",
Name: "EchoPatch",
Method: "PATCH",
Path: "/v1/example/echo_patch",
DefaultUrl: false,
ClientStream: false,
ServerStream: false,
})
mthList = append(mthList, xgen.GrpcRestHandler{
Input: &SimpleMessage{},
Output: &SimpleMessage{},
Service: "gid.EchoService",
Name: "EchoUnauthorized",
Method: "GET",
Path: "/v1/example/echo_unauthorized",
DefaultUrl: false,
ClientStream: false,
ServerStream: false,
})
xgen.Add(reflect.ValueOf(RegisterEchoServiceServer), mthList)
xgen.Add(reflect.ValueOf(RegisterEchoServiceHandlerServer), nil)
}
func RegisterEchoServiceRestServer(app fiber.Router, server EchoServiceServer) {
xerror.Assert(app == nil || server == nil, "app is nil or server is nil")
app.Add("POST", "/v1/example/echo/{id}", func(ctx *fiber.Ctx) error {
var req = new(SimpleMessage)
xerror.Panic(ctx.BodyParser(req))
var resp, err = server.Echo(ctx.UserContext(), req)
xerror.Panic(err)
return xerror.Wrap(ctx.JSON(resp))
})
app.Add("POST", "/v1/example/echo_body", func(ctx *fiber.Ctx) error {
var req = new(SimpleMessage)
xerror.Panic(ctx.BodyParser(req))
var resp, err = server.EchoBody(ctx.UserContext(), req)
xerror.Panic(err)
return xerror.Wrap(ctx.JSON(resp))
})
app.Add("DELETE", "/v1/example/echo_delete", func(ctx *fiber.Ctx) error {
var req = new(SimpleMessage)
xerror.Panic(ctx.BodyParser(req))
var resp, err = server.EchoDelete(ctx.UserContext(), req)
xerror.Panic(err)
return xerror.Wrap(ctx.JSON(resp))
})
app.Add("PATCH", "/v1/example/echo_patch", func(ctx *fiber.Ctx) error {
var req = new(DynamicMessageUpdate)
xerror.Panic(ctx.BodyParser(req))
var resp, err = server.EchoPatch(ctx.UserContext(), req)
xerror.Panic(err)
return xerror.Wrap(ctx.JSON(resp))
})
app.Add("GET", "/v1/example/echo_unauthorized", func(ctx *fiber.Ctx) error {
var req = new(SimpleMessage)
data := make(map[string][]string)
ctx.Context().QueryArgs().VisitAll(func(key []byte, val []byte) {
k := byteutil.ToStr(key)
v := byteutil.ToStr(val)
if strings.Contains(v, ",") && gutil.EqualFieldType(req, reflect.Slice, k) {
values := strings.Split(v, ",")
for i := 0; i < len(values); i++ {
data[k] = append(data[k], values[i])
}
} else {
data[k] = append(data[k], v)
}
})
xerror.Panic(gutil.MapFormByTag(req, data, "json"))
var resp, err = server.EchoUnauthorized(ctx.UserContext(), req)
xerror.Panic(err)
return xerror.Wrap(ctx.JSON(resp))
})
}