Use sling http client and add improved test assertions #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This one is a bit more extensive, but hopefully you'll find it useful as well. This PR starts with the
github.com/dghubble/sling
package. It's a pretty simple HTTP client package that makes it easy to build an API SDK like this one without having to roll your ownapi.go
with all the methods you created there. I find it super useful and I love the reduction in lines of code in the overall SDK package. With the addition ofsling
, this package can just focus on getting input in the right format and providing the right structs for deserializing the JSON we got back fromgeocodio
.To make sure all the output structs were correct, I used
github.com/mypricehealth/jsonassert
to verify all the JSON can be unmarshalled and marshalled back to JSON correctly. In doing so, I found a few places where the prior structs weren't setup correctly so I updated accordingly;HouseholdIncome
struct was using JSON tags on the fields, but they all contained commas in them. Unfortunately, commas in JSON tags don't work in Go (https://stackoverflow.com/a/25984685) due to the way tags are implemented. I reverted this back to amap[string]CensusDataPoint
to get it workingCongressionalDistrict.Proportion
had the wrong tagCongressionalDistrict
canada.go
to enable the newriding
andstatscan
features fromgeocodio
Zip.RecordType
andSchoolDistrict.Secondary
Finally, I did a few other things to clean things up.
address.go
andenv.go
,location.go
, andfields.go
intogeocodio.go
since they were such small files I didn't feel like they needed their own files.InputAddress
struct which offersaddress
,city
,state
,zip
fields separately. I enabled this capability for both single addresses and for batches.EnvOldAPIKey
github.com/stretchr/testify/assert
to reduce the number of lines doing test asserts.