Skip to content

Commit

Permalink
Patched Query & Query worker to return raw JSON for custom unmarshaling.
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-hansen committed May 16, 2022
1 parent 75efed2 commit e0fbfd4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client_manager_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c QueryManager) Query(fabric, query string, bindVars map[string]interface{

// Create a cursor for the query from the server
res = query_req.NewResponseForCreateCursor()
if err = c.client.Request(req, res); err != nil {
if err = c.client.requestJsonResponse(req, res); err != nil {
return nil, err
}

Expand All @@ -64,7 +64,7 @@ func (c QueryManager) Query(fabric, query string, bindVars map[string]interface{
// request update for the cursor
reqNext := query_req.NewRequestForReadNextCursor(fabric, res.Id)
responseNext := query_req.NewResponseForReadNextCursor()
if err = c.client.Request(reqNext, responseNext); err != nil {
if err = c.client.requestJsonResponse(reqNext, responseNext); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions client_manager_query_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c QueryWorkerManager) RunQueryWorker(fabric, workerName, bindVars string)

req := qw_req.NewRequestForRunQueryWorker(fabric, workerName, bindVars)
res = qw_req.NewResponseForRunQueryWorker()
if err = c.client.Request(req, res); err != nil {
if err = c.client.requestJsonResponse(req, res); err != nil {
return nil, err
}

Expand All @@ -53,7 +53,7 @@ func (c QueryWorkerManager) RunQueryWorker(fabric, workerName, bindVars string)
// request update for the cursor
reqNext := qw_req.NewRequestForReadNextCursor(fabric, res.Id)
responseNext := qw_req.NewResponseForReadNextCursor()
if err = c.client.Request(reqNext, responseNext); err != nil {
if err = c.client.requestJsonResponse(reqNext, responseNext); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion client_util_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func PrintRes(res types.Responder, verbose bool) {

func PrintJsonRes(res types.JsonResponder, verbose bool) {
if verbose {
println(res.String())
println(string(res.GetJsonMessage()))
}
}
5 changes: 5 additions & 0 deletions http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (c *Client) requestJsonResponse(req types.Requester, results types.JsonResp
}
// println(string(res.Body()))
results.SetJsonMessage(res.Body())
decErr := decode(res.Body(), results)
if decErr != nil {
// println("Decode error")
return decErr
}
return nil
}

Expand Down
11 changes: 10 additions & 1 deletion requests/query_req/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ type Cursor struct {
Id string `json:"id"`
Cached bool `json:"cached"`
Result Result `json:"result"`
json []byte `json:"raw"`
}

func (r *Cursor) IsResponse() {}
func (c *Cursor) IsJsonResponse() {}

func (c *Cursor) SetJsonMessage(rawJson []byte) {
c.json = rawJson
}

func (c *Cursor) GetJsonMessage() []byte {
return c.json
}

func (c Cursor) Update(r *Cursor) {
c.Code = r.Code
Expand Down
1 change: 1 addition & 0 deletions tests/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestQuery(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintQuery(res, verbose)
goC8.PrintJsonRes(res, verbose)
}

func TestTeardown(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/query_worker/query_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestRunQueryWorker(t *testing.T) {

assert.NoError(t, err)
assert.NotNil(t, res)
goC8.PrintRes(res, verbose)
goC8.PrintJsonRes(res, verbose)
}

func TestReadAllQueryWorkers(t *testing.T) {
Expand Down

0 comments on commit e0fbfd4

Please sign in to comment.