I'll point out a couple things, firstly, in the following snippet:
// FormatArticleRequest returns http.Request ready to do() and get an articlefunc(dtcDevtoClient)FormatArticleRequest(iint32)(r*http.Request,errerror){URL:=fmt.Sprintf(dtc.DevtoAPIURL+"articles/%d",i)r,err=http.NewRequest(http.MethodGet,URL,nil)iferr!=nil{returnnil,err}returnr,nil}
You are returning a *http.Request and an error which means you can simplify it like this:
// FormatArticleRequest returns http.Request ready to do() and get an articlefunc(dtcDevtoClient)FormatArticleRequest(iint32)(r*http.Request,errerror){URL:=fmt.Sprintf(dtc.DevtoAPIURL+"articles/%d",i)returnhttp.NewRequest(http.MethodGet,URL,nil)}
Later on in your worker, you are forgetting to check the errors on json.Unmarshal(body, &articles)
Other than that, good job on parameterizing the HTTP client instance. Were I to use your API client, I would certainly love to set my own timeouts etc. so this is the right way to go!
Thanks for the comment! Ungh! I keep forgetting that I can shorten the returns when I do it that way. One of these days! Good catch on the json.Unmarshal not sure how that snuck through, I'll make sure to fix that up before putting the code on GitHub.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey there!
I'll point out a couple things, firstly, in the following snippet:
You are returning a
*http.Request
and anerror
which means you can simplify it like this:Later on in your worker, you are forgetting to check the errors on
json.Unmarshal(body, &articles)
Other than that, good job on parameterizing the HTTP client instance. Were I to use your API client, I would certainly love to set my own timeouts etc. so this is the right way to go!
Good job!
Thanks for the comment! Ungh! I keep forgetting that I can shorten the returns when I do it that way. One of these days! Good catch on the
json.Unmarshal
not sure how that snuck through, I'll make sure to fix that up before putting the code on GitHub.