Problem in converting graph response to Valid Go Type

@core-devs This is not related to Dgraph but with GO code.

So Im hitting “:8080/query” end point for storing “Question” Information in dgraph. After hitting it, I get data in “response.Body” variable and the response was:


So even though the question has been saved, I want to query the dgraph using above uid and send all its informatin back as response, for that I created Struct :

type DgraphResponse struct { // HTTP Response
  Code    string
  Message string
  UIDS    struct {
	Question string

Then I decode the First Http’s response into JSON:

var dresp DgraphResponse

err = json.NewDecoder(resp.Body).Decode(dresp)

But above fmt.Println giving empty output. I’ll figure out what’s wrong but let me know if you find by seeing it. Here is the full code :

Go documentation is extremely useful and has full examples of how to do such standard things.

Error handling is extremely crucial, and I noticed that you don’t check for errors.

Also, @pawan, we can probably buy Go programming language book for @Rahul-Sagore and @adisha.

Sure @Rahul-Sagore and @adisha go ahead and order and we will reimburse the cost of you.

@mrjn Actually I did the same thing for Tags, and it was working fine. I’ll check what’s wrong.

And thanks for the book reference, I would probably buy Kindle Edition, since I can’t manage Hard books. :slight_smile:

1 Like

Print that error, it probably contains the reason for failure. Also, always handle all errors.

Yeah, I know handling error is so important.

I was testing that’s why I did not put it for every case. Will add it.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.