Weather API application that allows users to subscribe to weather updates for their city.
Ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/velosypedno/genesis-weather-api.git
-
Change work directory:
cd genesis-weather-api
-
Configure environmental variables:
Copy
.env.sample
go-task copy:env
NOTE:
.env
must be edited manually. You need to set smtp credentials, API key, etc. -
Build and up services by Docker Compose:
go-task up
This will start the following services:
postgres-wether
- container with postgres databasemigrator
- waits for the database to start and then runs the migrationsapi-weather
- starts after themigrator
finishes working, contains APIcron-wether
- starts after themigrator
finishes working, contains cron tasks to send email
-
To run all tests:
go-task test
-
To install the pre-commit Git hook that runs linter automatically before each commit:
go-task copy:hooks:pre-commit
-
To remove the pre-commit Git hook:
go-task rm:hooks:pre-commit
All routes are prefixed with /api
.
Method | Endpoint | Description |
---|---|---|
GET | /weather |
Get current weather for a given city. Requires ?city=CityName query. |
POST | /subscribe |
Subscribe a user to weather updates. Expects JSON body with email, city, and frequency (hourly or daily ). |
GET | /confirm/:token |
Confirm a subscription via token received by email. |
GET | /unsubscribe/:token |
Unsubscribe from weather notifications using the token. |
This project follows layered architecture with a clear division of responsibilities. The structure is organized into the following layers:
- Handlers – handle HTTP requests, validate input, and return responses.
- Services – contain business logic (e.g., subscriptions, confirmation, weather processing).
- Repositories – provide access to PostgreSQL and external APIs.
.
├── cmd/
│ ├── api/ # Main HTTP server startup
│ └── cron/ # Scheduled tasks for sending weather emails
└── internal/
├── config/
├── handlers/ # HTTP requests handlers
├── ioc/ # Dependency injection
├── models/
├── repos/ # Repositories
├── scheduler/ # Cron tasks setup
├── server/ # HTTP server setup
└── services/ # Business logic layer
This project is licensed under the MIT License - see the LICENSE file for details