This is Go application that fetches weather information from the OpenWeatherMap API based on user input and returns the weather data in JSON format.
- Fetch weather data for a specific city.
- Return weather data in JSON format.
- Error handling for missing API keys and invalid requests.
The following environment variables are used in the application:
- OPEN_WEATHER_API_KEY: API key for accessing the OpenWeatherMap API. Get your API key here
Ensure these variables are set before running the application.
To install the Weather App, follow these steps:
- Clone the repository:
git clone https://github.com/coolpythoncodes/weather-go-api.git- Navigate to the project directory:
cd weather-go-api- Set up environment variables by creating a .env file in the root directory and adding the necessary variables (see Environment Variables). Note: this is applicable to those using docker compose to build the app.
To run the Weather App(not applicable to people using docker compose),
Set your environment variable by running the following commands on your terminal
export OPEN_WEATHER_API_KEY="insert your api key here"go run main.goFor Docker fans
docker compose up --buildThe Weather App provides the following endpoints:
GET /weather/:city: Fetches weather data for the specified city.
Example:
curl http://localhost:8080/weather/LondonResponse:
{
"error": false,
"data": {
"name": "London",
"weather": [
{
"main": "Clouds",
"description": "scattered clouds"
}
],
"main": {
"temp": 12.34
}
}
}