Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather API

A simple weather API written in Go that fetches weather information from Visual Crossing and caches results in Redis.

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

Features

  • HTTP endpoint for weather lookup by city
  • Weather provider integration with Visual Crossing
  • Redis-backed caching layer
  • Configurable server, Redis, and cache settings via environment variables
  • Basic request validation and timeout handling

Requirements

  • Go 1.26 or later
  • Redis server for caching

Environment Variables

The application uses the following environment variables:

  • SERVER_HOST - server host address, default 0.0.0.0
  • SERVER_PORT - server port, default 8080
  • REDIS_ADDR - Redis address, default localhost:6379
  • REDIS_PASSWORD - Redis password, default empty
  • REDIS_DB - Redis database index, default 0
  • REDIS_PROTOCOL - Redis protocol version, default 3
  • WEATHER_API_KEY - Visual Crossing weather API key, required
  • CACHE_TTL - cache time to live, default 30m

Run Locally

  1. Install Go and start Redis.
  2. Set environment variables in a .env file or in your shell.
  3. Run the application:
cd /home/hazubeep/Documents/golang/weather-api
go run ./cmd

The service listens on http://SERVER_HOST:SERVER_PORT.

API

Request weather data using the /weather endpoint:

GET /weather?city={city}

Example:

curl "http://localhost:8080/weather?city=Bandung"

or:

curl "http://localhost:8080/weather?city=Bandung,ID"

Testing

Run the Go test suite:

go test ./...

Project Structure

  • cmd/main.go - application entry point and server setup
  • internal/config - configuration loading and validation
  • internal/client - Visual Crossing API client
  • internal/repository - Redis cache implementation
  • internal/service - weather business logic
  • internal/handler - HTTP request handling

About

A Simple weather API written in Go

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages