Original post

I hope I’m in the right place for this kind of questions. I started learning Go a few days ago when I got an idea for a simple little tool (or so I thought). My skill level is “none”, it’s my first time learning programming. Although I am familiar with most terms (working in software), I have zero familarity with the actual concepts and practices.

Here is what I’m trying to do: I GET request an API which returns a fairly large response. It delivers a maximum of 100 objects, with a cursor for the next 100 objects.

When I have all the data, I want to do some calculations with one of the fields of all objects that fit a certain criteria.

So right now I have two problems: How do I loop through a cursor pagination, and how do I get all results in my struct?

So much for the abstract. Here is the concrete stuff.

I want to query the API of the online game store Steam with an app id, get all the reviews, and then calculate (and print) some stuff like “average total time played of positive reviewers” (same for negative) and the like.

Here is what I got so far, github repo so I don’t paste 100 lines in here: https://github.com/kstork/steam_reviews_stats/blob/master/review_stats.go

So far I can get the first page (called with the cursor “*”) and get that into a struct.

I used a fairly simple tutorial to kick me off and they said its best practice to define it all if you know what the response is gonna look like, so I did.

It works so far – I can get to the data I want and do the math on it.

But only for the first page. I was thinking of either somehow getting it all into the GetReviews() method and somehow returning the complete struct, or figuring out how to loop GetReviews() as is and fill the struct in main.

I also need to figure out how to do it in a way that I only need to supply the appid, the first round it uses cursor=* and after that replace it with the cursor from the response.

I guess it would also be best practice to get most of the operations into their own methods, so I can do GetReviews(1234) followed by variable.AveragePositive(), variable.AverageNegative() and the like. Wait I would need an interface for that then, right?

Thanks for reading, and maybe even helping! 🙂