Please create a test case (snooth_test.go) which illustrates your problem: has the input as const string, tries to Unmarshal into your chosen struct, probably fails with error. All without making HTTP requests!
2018. május 14., hétfő 14:29:57 UTC+2 időpontban Luke IC a következőt írta: > > I've tried that, but I need to decode the JSON into a struct generated > from a .proto. Updating the code to use json.Unmarshal results in the > wines array from the response not decoding correctly, here is what I see > when printing the struct that I have unmarshalled into: > meta:<results:1489449 returned:15 status:1 > wines:<> wines:<> wines:<> > wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> wines:<> > wines:<> wines:<> wines:<> wines:<> > > Note the repeated values are empty. The relevant source code can be viewed > here: https://github.com/lukeic/vinogo/tree/feature/snooth/snooth > <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Flukeic%2Fvinogo%2Ftree%2Ffeature%2Fsnooth%2Fsnooth&sa=D&sntz=1&usg=AFQjCNFw1bOg4tMyH2nskcS46qw_S9Yusg>. > > Help figuring this out would be much appreciated as I've spent ages on it > now. > > > On Monday, 14 May 2018 17:46:58 UTC+10, Tamás Gulácsi wrote: >> >> It DOES parse with then encoding/json package: >> https://play.golang.org/p/IQzMm2tDI7w >> >> The protoc-generated code's Unmarshal parses a *Protocol Buffers* >> encoded byte stream, NOT JSON! >> >> >> 2018. május 14., hétfő 5:24:06 UTC+2 időpontban Luke IC a következőt írta: >>> >>> Hi all, >>> >>> I'm creating a microservice in Go, using protocol buffers and gRPC. It >>> interacts with a third-party API (Snooth) and I'm trying to unmarshal the >>> JSON response into a protobuf struct I've created, using the proto >>> package. >>> >>> Unmarshalling returns an unexpected EOF error. >>> >>> >>> I've summed up the details in full on this question at Stack Overflow: >>> https://stackoverflow.com/questions/50314476/why-does-unmarshalling-this-api-response-return-an-unexpected-eof >>> >>> >>> In addition to the information posted there, I've also tried using >>> strconv.Unquote before unmarshalling in line with the idea that the escaped >>> characters in the API response are causing a double-encode. But this didn't >>> work either. >>> >>> Any help would be greatly appreciated as I've been stuck on this for a >>> while now and feel there's something simple I'm missing. >>> >>> >>> Thanks. >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.