-
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 #5
Open
bitfield
wants to merge
33
commits into
umang-review
Choose a base branch
from
umang-full-content
base: umang-review
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Full Review #5
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
03d060e
Initial commit
qba73 962f6f6
Update README.md
qba73 29e94ec
initial commit
qba73 0344b29
Create go.yml
qba73 90a7890
Update README.md
qba73 55a0d25
gofmt
qba73 a20b210
Merge branch 'master' of github.com:qba73/meteo
qba73 23d424d
Update README.md
qba73 538a6f8
Update README.md
qba73 68404db
Update README.md
qba73 fa913ed
initial lib structure
qba73 d2390eb
Merge branch 'master' of github.com:qba73/meteo
qba73 67fb5a4
update docs
qba73 7c2ffc4
wip - construct a client
qba73 adacdc5
Add test data
qba73 16cf779
Update dependencies
qba73 ffcb0c8
Get weather for Lat Lon
qba73 f9f6d2d
Merge pull request #1 from qba73/latlon
qba73 aad1523
Add Geo coordinates lookup
qba73 cd9d95f
Merge branch 'request'
qba73 11ea492
Implement geolookup interface
qba73 a0f37ad
Added initial docs
qba73 d9492b3
Update go.yml
qba73 5c49400
Update README.md
qba73 c6e68ef
Update documentation
qba73 6621d7a
Update docs
qba73 03a65d2
Update README.md
qba73 bf677f8
Make tests more robust
qba73 fdd0911
Merge master into umang-full-content
bitfield 6637f6b
Update meteo.go
qba73 6c01d6a
Update meteo.go
qba73 5ddc66e
Update norway_test.go
qba73 6c68270
Update norway_test.go
qba73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout main | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run unit tests | ||
run: | | ||
make test-ci | ||
env: | ||
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
*.html | ||
|
||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
vendor/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Jakub Jarosz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.PHONY: help check cover test tidy | ||
|
||
ROOT := $(PWD) | ||
GO_HTML_COV := ./coverage.html | ||
GO_TEST_OUTFILE := ./c.out | ||
GO_DOCKER_IMAGE := golang:1.17 | ||
GO_DOCKER_CONTAINER := meteo-container | ||
CC_TEST_REPORTER_ID := ${CC_TEST_REPORTER_ID} | ||
CC_PREFIX := github.com/qba73/meteo | ||
|
||
|
||
define PRINT_HELP_PYSCRIPT | ||
import re, sys | ||
|
||
for line in sys.stdin: | ||
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) | ||
if match: | ||
target, help = match.groups() | ||
print("%-20s %s" % (target, help)) | ||
endef | ||
export PRINT_HELP_PYSCRIPT | ||
|
||
default: help | ||
|
||
help: | ||
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) | ||
|
||
check: ## Run static check analyzer | ||
staticcheck ./... | ||
|
||
cover: ## Run unit tests and generate test coverage report | ||
go test -v ./... -count=1 -covermode=count -coverprofile=coverage.out | ||
go tool cover -html coverage.out | ||
staticcheck ./... | ||
|
||
test: ## Run unit tests locally | ||
go test -v ./... -count=1 | ||
staticcheck ./... | ||
|
||
# MODULES | ||
tidy: ## Run go mod tidy and vendor | ||
go mod tidy | ||
go mod vendor | ||
|
||
|
||
clean: ## Remove docker container if exist | ||
docker rm -f ${GO_DOCKER_CONTAINER} || true | ||
|
||
testdocker: ## Run unittests inside a container | ||
docker run -w /app -v ${ROOT}:/app ${GO_DOCKER_IMAGE} go test ./... -coverprofile=${GO_TEST_OUTFILE} | ||
docker run -w /app -v ${ROOT}:/app ${GO_DOCKER_IMAGE} go tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV} | ||
|
||
lint: ## Run linter inside container | ||
docker run --rm -v ${ROOT}:/data cytopia/golint . | ||
|
||
# Custom logic for code climate | ||
_before-cc: | ||
# Download CC test reported | ||
docker run -w /app -v ${ROOT}:/app ${GO_DOCKER_IMAGE} \ | ||
/bin/bash -c \ | ||
"curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter" | ||
|
||
# Make reporter executable | ||
docker run -w /app -v ${ROOT}:/app ${GO_DOCKER_IMAGE} chmod +x ./cc-test-reporter | ||
|
||
# Run before build | ||
docker run -w /app -v ${ROOT}:/app \ | ||
-e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} ${GO_DOCKER_IMAGE} \ | ||
./cc-test-reporter before-build | ||
|
||
_after-cc: | ||
# Handle custom prefix | ||
$(eval PREFIX=${CC_PREFIX}) | ||
ifdef prefix | ||
$(eval PREFIX=${prefix}) | ||
endif | ||
# Upload data to CC | ||
docker run -w /app -v ${ROOT}:/app \ | ||
-e CC_TEST_REPORTER_ID=${CC_TEST_REPORTER_ID} \ | ||
${GO_DOCKER_IMAGE} ./cc-test-reporter after-build --prefix ${PREFIX} | ||
|
||
test-ci: _before-cc testdocker _after-cc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
![Go](https://github.com/qba73/meteo/workflows/Go/badge.svg) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/qba73/meteo)](https://goreportcard.com/report/github.com/qba73/meteo) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/4afc34a390da95ed9327/maintainability)](https://codeclimate.com/github/qba73/meteo/maintainability) | ||
[![Test Coverage](https://api.codeclimate.com/v1/badges/4afc34a390da95ed9327/test_coverage)](https://codeclimate.com/github/qba73/meteo/test_coverage) | ||
|
||
|
||
# meteo | ||
|
||
Meteo is a Go client library for the weather and meteorological forecast from [Yr](https://www.yr.no/en). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great README! Maybe move the example up to the top, so it's the first thing users see? |
||
|
||
Disclaimer: | ||
|
||
Weather forecast from Yr, delivered by the Norwegian Meteorological Institute and NRK. | ||
|
||
# Usage | ||
|
||
## Preconditions | ||
|
||
You must register your user agent string in the [YR.NO service](https://developer.yr.no/doc/TermsOfService/) and your user name in the [GeoNames service](https://www.geonames.org/login) to use the package. | ||
|
||
|
||
## Installation | ||
``` | ||
$ go get git@github.com:qba73/meteo.git | ||
``` | ||
|
||
## Default | ||
|
||
Export ```GEO_USERNAME``` env var that you registered with GeoNames.org. | ||
|
||
Example: | ||
``` | ||
$ export GEO_USERNAME=Jane123 | ||
``` | ||
Use the ```meteo``` package in your application: | ||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"github.com/qba73/meteo" | ||
) | ||
|
||
func main() { | ||
// Get weather status for Castlebar in Ireland: | ||
weather, err := meteo.GetWeather("Castlebar", "IE") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
// Print out weather string. | ||
// Example: Lightrain 8.3°C | ||
fmt.Println(weather) | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/qba73/meteo" | ||
|
||
func main() { | ||
meteo.RunCLI() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package meteo is a client library for the weather | ||
// API data provided by the Norwegian Meteorological Institute. | ||
package meteo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Example 1") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/qba73/meteo" | ||
) | ||
|
||
func main() { | ||
// Get weather status for city Castlebar in Ireland: | ||
weather, err := meteo.GetWeather("Castlebar", "IE") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
// Print out weather string. | ||
// Example: Lightrain 8.3°C | ||
fmt.Println(weather) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/qba73/meteo" | ||
) | ||
|
||
func main() { | ||
// Get coordinates using a default Geo client | ||
user := os.Getenv("GEO_USERNAME") | ||
|
||
coord, err := meteo.GetCoordinates("Castlebar", "IE", user) | ||
if err != nil { | ||
println(err) | ||
} | ||
|
||
fmt.Printf("Lat: %.2f, Lng: %.2f for %s in country %s\n", coord.Lat, coord.Lng, coord.PlaceName, coord.CountryCode) | ||
// It returns: | ||
// Lat: 53.85, Lng: -9.30 for Castlebar in country IE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/qba73/meteo | ||
|
||
go 1.17 | ||
|
||
require github.com/google/go-cmp v0.5.6 | ||
|
||
require golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= | ||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package meteo | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const ( | ||
userAgent = "Meteo/0.1 https://github.com/qba73/meteo" | ||
) | ||
|
||
// Weather represents weather conditions | ||
// in a geographical region. | ||
type Weather struct { | ||
Summary string | ||
Temp float64 | ||
} | ||
|
||
// String implements stringer interface. | ||
func (w Weather) String() string { | ||
return fmt.Sprintf("%s %.1f°C", strings.Title(w.Summary), w.Temp) | ||
} | ||
|
||
// NameResolver interface is used by an Meteo Client | ||
// to obtain geo coordinates for given place located in | ||
// a country identified by country id. | ||
type NameResolver interface { | ||
// GetCoordinates takes place and country code | ||
// and returns geo information like lat and lng. | ||
GetCoordinates(placeName, country string) (Place, error) | ||
} | ||
|
||
// RunCLI is a main function that runs the cli machinery. | ||
func RunCLI() { | ||
uname := os.Getenv("GEO_USERNAME") | ||
resolver, err := NewWikipediaClient(uname) | ||
qba73 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
qba73 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
c, err := NewNorwayClient(resolver) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Printing to standard error makes sense! |
||
os.Exit(1) | ||
} | ||
w, err := c.GetForecast("Castlebar", "IE") | ||
qba73 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
fmt.Println(w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package meteo_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/qba73/meteo" | ||
) | ||
|
||
func TestWeatherStringFormat(t *testing.T) { | ||
t.Parallel() | ||
w := meteo.Weather{ | ||
Summary: "sunny", | ||
Temp: -3.12, | ||
} | ||
out := bytes.Buffer{} | ||
fmt.Fprint(&out, w) | ||
got := out.String() | ||
want := "Sunny -3.1°C" | ||
if want != got { | ||
t.Errorf("want %s, got %s", want, got) | ||
} | ||
} |
Oops, something went wrong.
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.
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.
These badges look nice!