-
Notifications
You must be signed in to change notification settings - Fork 2
/
idl_service.go
104 lines (86 loc) · 2.26 KB
/
idl_service.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
// Code generated by hertz generator.
package gateway
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/protocol/consts"
manager "github.com/huangwei021230/api-gateway/hertz-server/biz/handler/idl"
gateway "github.com/huangwei021230/api-gateway/hertz-server/biz/model/gateway"
)
// SearchForService .
// @router /search-for-service [POST]
func SearchForService(ctx context.Context, c *app.RequestContext) {
var err error
var req gateway.ServiceReq
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
resp := new(gateway.Service)
resp, _ = manager.GetService(req.ServiceName)
c.JSON(consts.StatusOK, resp)
}
// AddService .
// @router /add-service [POST]
func AddService(ctx context.Context, c *app.RequestContext) {
var err error
var req gateway.Service
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
resp := new(gateway.SuccessResp)
manager.AddService(req)
resp = &gateway.SuccessResp{
Success: true,
Msg: req.Name,
}
c.JSON(consts.StatusOK, resp)
}
// DelService .
// @router /delete-service [POST]
func DelService(ctx context.Context, c *app.RequestContext) {
var err error
var req gateway.ServiceReq
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
resp := new(gateway.SuccessResp)
manager.DelService(req.ServiceName)
resp = &gateway.SuccessResp{
Success: true,
Msg: "Delete " + req.ServiceName,
}
c.JSON(consts.StatusOK, resp)
}
// EditService .
// @router /edit-service [POST]
func EditService(ctx context.Context, c *app.RequestContext) {
var err error
var req gateway.Service
err = c.BindAndValidate(&req)
if err != nil {
c.String(consts.StatusBadRequest, err.Error())
return
}
resp := new(gateway.SuccessResp)
manager.EditService(req)
resp = &gateway.SuccessResp{
Success: true,
Msg: "Update " + req.Name + " success",
}
c.JSON(consts.StatusOK, resp)
}
// ListAllService .
// @router /list-all-service [POST]
func ListAllService(ctx context.Context, c *app.RequestContext) {
var _ error
resp := new([]*gateway.Service)
services := manager.ListAllService()
resp = &services
c.JSON(consts.StatusOK, resp)
}