func HandleGetAddresses(ctx *web.Context) { b := new(Response) b.Response = string(GetAddresses()) b.Success = true j, err := json.Marshal(b) if err != nil { reportResults(ctx, err.Error(), false) return } ctx.ContentType("json") ctx.Write(j) }
// True is success! False is failure. The Response is what the CLI // should report. func reportResults(ctx *web.Context, response string, success bool) { b := Response{ Response: response, Success: success, } if p, err := json.Marshal(b); err != nil { ctx.WriteHeader(httpBad) return } else { ctx.ContentType("json") ctx.Write(p) } }
func HandleGetTransactions(ctx *web.Context) { b := new(Response) txt, err := GetTransactions(ctx) if err != nil { reportResults(ctx, err.Error(), false) return } b.Response = string(txt) b.Success = true j, err := json.Marshal(b) if err != nil { reportResults(ctx, err.Error(), false) return } ctx.ContentType("json") ctx.Write(j) }