Project from roadmap.sh built using Go.
This API is just a simple API wrapper that fetches weather data from an external source.
As a prerequisite, sign up for a redis account to use as a cache for each request. Additionally, create an account with visual crossing to obtain an API key for the weather data. Both of these services are free. The rate limit is set to a maximum of 5 requests per 10 minutes per IP address. If no requests are made from the same IP address within 30 minutes, the rate limit counter will be reset.
- Clone this repo
- Create environment variables or use a
.env
file (must be placed in configs folder). Edit theconfigs.json
.
redis_username=
redis_password=
visual_crossing_api_key=
{
"Address": "0.0.0.0:8080",
"ReadTimeout": 200, // seconds
"WriteTimeout": 600, // seconds
"CacheExpire": 30 // minutes
}
- run project from the project's root directory:
go run ./cmd/myweather-api/main.go
docker build -t myweather-api .
docker run -p <port1>:<port2> myweather-api
Note: The port2 is the port from config.json, which is needed to expose the port from the docker container.
Builds executable and copies all configs into the bin
directory
make all
OPTIONAL:
It is possible to build this application for a Raspberry Pi 5 by doing the command:
make build-raspdist
. This will create the executable suitable for the device.
Once the application is running, perform a GET request on the endpoint.
curl http://localhost:8080/api/v1/weather?city=London
- Response Format: This will return weather information for the city of London in JSON format.
Listed below are topics and skills I learned from this: