Skip to content

Full Review#2

Open
qba73 wants to merge 29 commits intoprme-full-reviewfrom
prme-full-content
Open

Full Review#2
qba73 wants to merge 29 commits intoprme-full-reviewfrom
prme-full-content

Conversation

@qba73
Copy link
Copy Markdown
Owner

@qba73 qba73 commented Nov 3, 2021

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.

@qba73 qba73 added the enhancement New feature or request label Nov 3, 2021
Copy link
Copy Markdown
Collaborator

@bitfield bitfield left a 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.

Comment thread wikipedia_test.go
t.Fatalf("GetCoordinates('Castlebar', 'IE') got err %v", err)
}
want := meteo.Place{
Lng: -9.2988,
Copy link
Copy Markdown
Collaborator

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.

Comment thread wikipedia.go

var wp wikipediaPlaces
if err := json.NewDecoder(res.Body).Decode(&wp); err != nil {
return Place{}, fmt.Errorf("decoding response %w", err)
Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented

Comment thread norway.go
// GetWeather returns current weather for given
// place and country using default client for the Norwegian
// meteorological Institute.
func GetWeather(place, country string) (Weather, error) {
Copy link
Copy Markdown
Collaborator

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.

Suggested change
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.

Copy link
Copy Markdown
Collaborator

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.)

Comment thread norway.go
if err != nil {
return Weather{}, err
}
c, err := NewNorwayClient(resolver)
Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Owner Author

@qba73 qba73 Nov 7, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants