Skip to content

Commit

Permalink
Merge pull request #127 from numary/feature/num-288-remove-response-w…
Browse files Browse the repository at this point in the history
…rapper-n-ledger-api

Remove 'ok' property on json responses.
  • Loading branch information
flemzord authored Jan 19, 2022
2 parents 9c03790 + f600702 commit 01de87f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
7 changes: 1 addition & 6 deletions pkg/api/controllers/base_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import (
// Controllers struct
type BaseController struct{}

type BaseResponse struct {
Ok bool `json:"ok"`
}
type BaseResponse struct {}

func (ctl *BaseController) response(c *gin.Context, status int, data interface{}) {
if data == nil {
c.Status(status)
}
if reflect.TypeOf(data) == reflect.TypeOf(query.Cursor{}) {
c.JSON(status, gin.H{
"ok": true,
"cursor": data,
})
} else {
c.JSON(status, gin.H{
"ok": true,
"data": data,
})
}
Expand All @@ -34,7 +30,6 @@ func (ctl *BaseController) response(c *gin.Context, status int, data interface{}
func (ctl *BaseController) responseError(c *gin.Context, status int, err error) {
c.Abort()
c.AbortWithStatusJSON(status, gin.H{
"ok": false,
"error": true,
"error_code": status,
"error_message": err.Error(),
Expand Down
4 changes: 1 addition & 3 deletions pkg/api/controllers/script_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ func (ctl *ScriptController) PostScript(c *gin.Context) {

err := l.(*ledger.Ledger).Execute(c.Request.Context(), script)

res := gin.H{
"ok": err == nil,
}
res := gin.H{}

if err != nil {
errStr := err.Error()
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/middlewares/ledger_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func (m *LedgerMiddleware) LedgerMiddleware() gin.HandlerFunc {
l, err := m.resolver.GetLedger(c.Request.Context(), name)
if err != nil {
c.JSON(400, gin.H{
"ok": false,
"err": err.Error(),
"error": true,
"error_code": 400,
"error_message": err.Error(),
})
}
defer func() {
Expand Down

0 comments on commit 01de87f

Please sign in to comment.