Skip to content

devrapture/weather-go-api

Repository files navigation

GO Weather App

This is Go application that fetches weather information from the OpenWeatherMap API based on user input and returns the weather data in JSON format.

Table of Contents

Features

  • Fetch weather data for a specific city.
  • Return weather data in JSON format.
  • Error handling for missing API keys and invalid requests.

Environment Variables

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.

Installation

To install the Weather App, follow these steps:

  1. Clone the repository:
git clone https://github.com/coolpythoncodes/weather-go-api.git
  1. Navigate to the project directory:
cd weather-go-api
  1. 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.

Usage

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

For Docker fans

docker compose up --build

Endpoints

The Weather App provides the following endpoints:

GET /weather/:city: Fetches weather data for the specified city.

Example:

curl http://localhost:8080/weather/London

Response:

{
	"error": false,
	"data": {
		"name": "London",
		"weather": [
			{
				"main": "Clouds",
				"description": "scattered clouds"
			}
		],
		"main": {
			"temp": 12.34
		}
	}
}

About

This is Go application that fetches weather information from the OpenWeatherMap API based on user input and returns the weather data in JSON format.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors