/
base_jrpc.go
38 lines (34 loc) · 940 Bytes
/
base_jrpc.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
package busi
import (
"fmt"
"github.com/dtm-labs/client/dtmcli/dtmimp"
"github.com/dtm-labs/client/dtmcli/logger"
"github.com/dtm-labs/dtm-examples/dtmutil"
"github.com/gin-gonic/gin"
)
// BusiJrpcURL url prefix for busi
var BusiJrpcURL = fmt.Sprintf("http://localhost:%d/api/json-rpc?method=", BusiPort)
func addJrpcRoute(app *gin.Engine) {
app.POST("/api/json-rpc", dtmutil.WrapHandler(func(c *gin.Context) interface{} {
var data map[string]interface{}
err := c.BindJSON(&data)
dtmimp.E2P(err)
logger.Debugf("method is: %s", data["method"])
var rerr map[string]interface{}
r := MainSwitch.JrpcResult.Fetch()
if r != "" {
rerr = map[string]interface{}{
"code": map[string]int{
"FAILURE": dtmimp.JrpcCodeFailure,
"ONGOING": dtmimp.JrpcCodeOngoing,
"OTHER": -23977,
},
}
}
return map[string]interface{}{
"jsonrpc": "2.0",
"error": rerr,
"id": data["id"],
}
}))
}