forked from fagongzi/manba
/
api_routing.go
56 lines (46 loc) · 1003 Bytes
/
api_routing.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
package server
import (
"net/http"
"github.com/fagongzi/gateway/pkg/model"
"github.com/labstack/echo"
)
func (server *AdminServer) getRoutings() echo.HandlerFunc {
return func(c echo.Context) error {
var errstr string
code := CodeSuccess
routings, err := server.store.GetRoutings()
if err != nil {
errstr = err.Error()
code = CodeError
}
return c.JSON(http.StatusOK, &Result{
Code: code,
Error: errstr,
Value: routings,
})
}
}
func (server *AdminServer) newRouting() echo.HandlerFunc {
return func(c echo.Context) error {
var errstr string
code := CodeSuccess
routing, err := model.UnMarshalRoutingFromReader(c.Request().Body())
if err == nil {
err = routing.Check()
}
if nil != err {
errstr = err.Error()
code = CodeError
} else {
err := server.store.SaveRouting(routing)
if nil != err {
errstr = err.Error()
code = CodeError
}
}
return c.JSON(http.StatusOK, &Result{
Code: code,
Error: errstr,
})
}
}