forked from alash3al/sqler
/
routes.go
56 lines (47 loc) · 1.15 KB
/
routes.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
// Copyright 2018 The SQLer Authors. All rights reserved.
// Use of this source code is governed by a Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"github.com/labstack/echo"
)
// routeIndex - the index route
func routeIndex(c echo.Context) error {
return c.JSON(200, map[string]interface{}{
"success": true,
"message": "Weclome!",
})
}
// routeExecMacro - execute the requested macro
func routeExecMacro(c echo.Context) error {
macro := c.Get("macro").(*Macro)
input := make(map[string]interface{})
body := make(map[string]interface{})
c.Bind(&body)
for k := range c.QueryParams() {
input[k] = c.QueryParam(k)
}
for k, v := range body {
input[k] = v
}
if len(macro.Rules) > 0 {
result := Validate(input, macro.Rules)
if len(result) > 0 {
return c.JSON(422, map[string]interface{}{
"success": false,
"errors": result,
})
}
}
out, err := macrosManager.Call(c.Param("macro"), input)
if err != nil {
return c.JSON(500, map[string]interface{}{
"success": false,
"error": err.Error(),
})
}
return c.JSON(200, map[string]interface{}{
"success": true,
"data": out,
})
}