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:

 {"code":"ErrorOk","message":"Done","uids":{"question":11411066080515171301}}

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)
fmt.Println(dresp.Code)
fmt.Println(dresp.UIDS.Question)

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 : https://github.com/dgraph-io/gru/blob/feature/admin-backend/gruadmin/main.go

Go documentation is extremely useful and has full examples of how to do such standard things.
https://golang.org/pkg/net/http/

Error handling is extremely crucial, and I noticed that you don’t check for errors.
https://github.com/dgraph-io/gru/blob/feature/admin-backend/gruadmin/main.go#L87

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

Sure @Rahul-Sagore and @adisha go ahead and order Go Programming Language, The (Addison-Wesley Professional Computing Series) eBook: A., Donovan Alan A., Kernighan Brian W.: Amazon.in: Kindle Store 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.