forked from alash3al/sqler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.go
58 lines (48 loc) · 1.16 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
57
58
// 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 (
"strings"
"github.com/labstack/echo"
)
// routeIndex - the index route
func routeIndex(c echo.Context) error {
return c.JSON(200, map[string]interface{}{
"success": true,
"message": "Welcome!",
})
}
// 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
}
headers := c.Request().Header
for k, v := range headers {
input["http_"+strings.Replace(strings.ToLower(k), "-", "_", -1)] = v[0]
}
out, err := macro.Call(input)
if err != nil {
code := errStatusCodeMap[err]
if code < 1 {
code = 500
}
return c.JSON(code, map[string]interface{}{
"success": false,
"error": err.Error(),
"data": out,
})
}
return c.JSON(200, map[string]interface{}{
"success": true,
"data": out,
})
}