-
Notifications
You must be signed in to change notification settings - Fork 0
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
Full Review #2
base: prme-full-review
Are you sure you want to change the base?
Full Review #2
Conversation
Get weather for Lat Lon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far! Try adding an alternate weather provider (such as OpenWeatherMap) and see how that plays with your existing API.
t.Fatalf("GetCoordinates('Castlebar', 'IE') got err %v", err) | ||
} | ||
want := meteo.Place{ | ||
Lng: -9.2988, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible we might run into a floating-point imprecision issue comparing these values, isn't it? If Wikipedia provides four decimal places of precision, what about storing the lat and long as int
:
Longitude: -92988,
Latitude: 538608
You can always insert the decimal point for display.
|
||
var wp wikipediaPlaces | ||
if err := json.NewDecoder(res.Body).Decode(&wp); err != nil { | ||
return Place{}, fmt.Errorf("decoding response %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest reading all the body with io.ReadAll
and then passing the resulting []byte
to json.Unmarshal
. In the event of a parsing error, it'll be nice to have the JSON data to display to the user. Using the Decode
API, we wouldn't have that, because consuming the reader destroys its contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented
// GetWeather returns current weather for given | ||
// place and country using default client for the Norwegian | ||
// meteorological Institute. | ||
func GetWeather(place, country string) (Weather, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different weather providers have different ways to specify the location, so perhaps we need to think more generally when defining our GetWeather
function, because it'll become frozen as an interface.
func GetWeather(place, country string) (Weather, error) { | |
func GetWeather(location string) (Weather, error) { |
Each provider (for example Norway) can interpret that location string according to its own needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Alternatively, you could define a struct Location
, with multiple ways of specifying a location. To save paperwork, you could then provide a few different ways to specify a location, by city-country, by lat/long, What3Words, and so on.)
if err != nil { | ||
return Weather{}, err | ||
} | ||
c, err := NewNorwayClient(resolver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the geo-resolver stuff is independent enough to be moved out into its own package, isn't it? I mean, I can see myself using it for something not related to weather, so I wouldn't want to import the whole meteo
package just to get the lat/long functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented. For now in the same repo, but I am thinking in the future to move it to a separate repo and add more functionality to the library to cover all functionality of the current GeoNames web services (https://www.geonames.org/export/ws-overview.html)
A full review of the entire repository. When this PR is complete, be sure to manually merge its head branch into the main branch for this repository.