Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/otumian-empire/go-weather-api-consumer
https://github.com/otumian-empire/go-weather-api-consumer
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/otumian-empire/go-weather-api-consumer
- Owner: Otumian-empire
- Created: 2023-08-12T21:47:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-13T05:51:17.000Z (over 1 year ago)
- Last Synced: 2024-06-19T16:16:33.858Z (8 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Consuming weather API
In this project we consume an API from, [weatherapi](https://www.weatherapi.com/). Sign up and get your API key. Create a `.env` file as `sample.env`.
## Run
`make run` or `go run cmd/main.go`
## Resource
- [how-to-make-an-http-server-in-go](https://www.digitalocean.com/community/tutorials/how-to-make-an-http-server-in-go)
- [how-to-make-http-requests-in-go](https://www.digitalocean.com/community/tutorials/how-to-make-http-requests-in-go)## Request and Response
```sh
# request
curl --location 'localhost:3000/?city=Accra'
``````json
{
"location": {
"name": "Accra",
"region": "Greater Accra",
"country": "Ghana",
"lat": 5.55,
"lon": -0.22,
"tz_id": "Africa/Accra",
"localtime_epoch": 1691876472,
"localtime": "2023-08-12 21:41"
},
"current": {
"last_updated_epoch": 1691875800,
"last_updated": "2023-08-12 21:30",
"temp_c": 25.0,
"temp_f": 77.0,
"is_day": 0,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/night/116.png",
"code": 1003
},
"wind_mph": 13.6,
"wind_kph": 22.0,
"wind_degree": 220,
"wind_dir": "SW",
"pressure_mb": 1013.0,
"pressure_in": 29.91,
"precip_mm": 0.0,
"precip_in": 0.0,
"humidity": 89,
"cloud": 50,
"feelslike_c": 27.3,
"feelslike_f": 81.1,
"vis_km": 10.0,
"vis_miles": 6.0,
"uv": 1.0,
"gust_mph": 18.1,
"gust_kph": 29.2
}
}
``````sh
curl --location 'localhost:3000/format?city=Accra'```
```json
{
"location": {
"name": "Accra",
"region": "Greater Accra",
"country": "Ghana",
"lat": 5.55,
"lon": -0.22,
"tz_id": "Africa/Accra",
"localtime": "2023-08-12 21:41"
},
"current": {
"last_updated": "2023-08-12 21:30",
"temp_c": 25,
"condition": {
"text": "Partly cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/night/116.png",
"code": 1003
},
"wind_kph": 22,
"wind_degree": 220,
"wind_dir": "SW",
"pressure_mb": 1013,
"precip_mm": 0,
"humidity": 89,
"cloud": 50,
"vis_km": 10,
"uv": 1,
"gust_kph": 29.2
}
}
```