Socket
Book a DemoInstallSign in
Socket

github.com/r3iwan/weather-api

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/r3iwan/weather-api

Source
Go
Version
v0.0.0-20250109040924-93d58d2be410
Version published
Created
Source

Weather API Service

This is a Go-based Weather API service that provides weather data for a given city using the Visual Crossing Weather API. The service caches the results in Redis for faster responses and efficient resource usage.

Project URL: https://roadmap.sh/projects/weather-api-wrapper-service

Features

  • Get Current Weather: Fetch weather information for a specified city and unit (e.g., metric or imperial).
  • Redis Caching: Weather data is cached for 12 hours to improve performance and reduce API calls.
  • Gin Framework: Utilizes the Gin framework for HTTP routing and JSON responses.
  • Error Handling: Handles common errors such as missing API keys, invalid parameters, and Redis issues.

API Endpoints

/weather

Fetch weather information for a specified city.

Query Parameters:

  • city (required): The name of the city.
  • unit (required): The unit for temperature (metric or imperial).

Example Request:

GET http://localhost:8080/weather?city=London&unit=metric

Example Response:

{
  "resolvedAddress": "London, England, United Kingdom",
  "timezone": "Europe/London",
  "days": [
    {
      "datetime": "2025-01-09",
      "temp": 7.2,
      "conditions": "Partially Cloudy",
      "description": "A mix of clouds and sun."
    }
  ]
}

How to run:

Prerequisites

Go installed on your system. Redis running locally. Visual Crossing API Key for accessing weather data. .env file with the following content:

1.Clone the repository:

git clone https://github.com/r3iwan/weather-api-service.git
cd weather-api-service

2.Install dependencies:

go mod tidy

3.Run the application:

go run main.go

4.Access the API at http://localhost:8080/weather.

FAQs

Package last updated on 09 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts