-
Notifications
You must be signed in to change notification settings - Fork 1
/
errapi_http.pb.go
98 lines (88 loc) · 2.23 KB
/
errapi_http.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
// Code generated by protoc-gen-zoo-http. DO NOT EDIT.
// versions:
// - protoc-gen-zoo-http v0.1.0
// - protoc (unknown)
// source: errapi/errapi.proto
package errapi
import (
context "context"
gin "github.com/gin-gonic/gin"
server "github.com/iobrother/zoo/core/transport/http/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = context.TODO
var _ = gin.New
var _ = server.NewServer
type ErrAPIHTTPService interface {
// SayHello ...
SayHello(context.Context, *HelloRequest) (*HelloReply, error)
// TestError ...
TestError(context.Context, *ErrorRequest) (*ErrorReply, error)
}
func RegisterErrAPIHTTPService(g *gin.RouterGroup, svc ErrAPIHTTPService) {
r := g.Group("")
r.GET("/hello/:name", _ErrAPI_SayHello0_HTTP_Handler(svc))
r.GET("/error/:name", _ErrAPI_TestError0_HTTP_Handler(svc))
}
func _ErrAPI_SayHello0_HTTP_Handler(svc ErrAPIHTTPService) gin.HandlerFunc {
return func(ctx *gin.Context) {
c := &server.Context{Context: ctx}
shouldBind := func(req *HelloRequest) error {
if err := c.ShouldBindQuery(req); err != nil {
return err
}
if err := c.ShouldBindUri(req); err != nil {
return err
}
return nil
}
var err error
var req HelloRequest
var rsp *HelloReply
if err = shouldBind(&req); err != nil {
c.SetError(err)
return
}
rsp, err = svc.SayHello(c.Request.Context(), &req)
if err != nil {
c.SetError(err)
return
}
if c.ContentType() == "application/x-protobuf" {
c.ProtoBuf(200, rsp)
} else {
c.JSON(200, rsp)
}
}
}
func _ErrAPI_TestError0_HTTP_Handler(svc ErrAPIHTTPService) gin.HandlerFunc {
return func(ctx *gin.Context) {
c := &server.Context{Context: ctx}
shouldBind := func(req *ErrorRequest) error {
if err := c.ShouldBindQuery(req); err != nil {
return err
}
if err := c.ShouldBindUri(req); err != nil {
return err
}
return nil
}
var err error
var req ErrorRequest
var rsp *ErrorReply
if err = shouldBind(&req); err != nil {
c.SetError(err)
return
}
rsp, err = svc.TestError(c.Request.Context(), &req)
if err != nil {
c.SetError(err)
return
}
if c.ContentType() == "application/x-protobuf" {
c.ProtoBuf(200, rsp)
} else {
c.JSON(200, rsp)
}
}
}