Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reddit Comments #1

Open
jzelinskie opened this issue May 19, 2014 · 4 comments
Open

Reddit Comments #1

jzelinskie opened this issue May 19, 2014 · 4 comments

Comments

@jzelinskie
Copy link
Owner

We're currently using a slapped together implementation to fetch comments from reddit.com. I'd like to completely model the whole thing out using static types and just encoding/json.Unmarshal() the whole thing. A lot of the complexity around the type hierarchy needed to parse the JSON can be hidden by struct embedding.

However, the "replies" field on comments either returns a list of objects or empty string if there are none. Sadly, I think this will require some kind of run-time type assertion.

@rendom
Copy link

rendom commented Aug 16, 2014

Is it not possible to make use of omitempty?

@jzelinskie
Copy link
Owner Author

Nope, I tried here. The problem is that the empty "replies" should be an [] not a "". It's basically a mismatch between a loosely-typed language (JavaScript) and a strongly typed language (Go).

@gmbuell
Copy link

gmbuell commented Aug 30, 2016

You just need to type alias []Comment and then implement the Unmarshaller interface. See example here:
https://play.golang.org/p/Gs9DxuKqBx

@jzelinskie
Copy link
Owner Author

Yep. That'd definitely work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants