@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
mrjn
(Manish R Jain)
September 16, 2016, 1:35am
2
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 .
pawan
(Pawan Rawal)
September 16, 2016, 3:02am
3
@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.
1 Like
mrjn
(Manish R Jain)
September 16, 2016, 7:52am
5
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
system
(system)
Closed
November 28, 2017, 1:00am
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.