This Code uses OpenWeather API to fetch and the store weather data to a MySQL database which can be accessed by an REST API Endpoint.
REST APIs
No. |
API Endpoint |
HTTP Method |
Description |
1. |
/weather |
POST |
Fetch Data from OpenWeather API |
2. |
/weather/ {cityName} |
GET |
Get Data from the MySQL DB |
Steps to Run
Paste the following Commands on your terminal:
Step 1: Create a Database
mysql -u root -p
CREATE DATABASE weather-information-system;
Step 2: Import the Database Schema
mysql -u root -p weather-information-system < weather-information-system.sql
Step 3: Import the Go Modules/Dependencies
go get -v ./...
Step 4: Run the Code
go run main.go
Step 5: Access the Endpoints
You can use Postman to access the REST API Endpoints mentioned above.
(The service runs on "http://localhost:9001")
Folder Structure:
.
├── cmd
│ ├── database
│ │ └── connection.go
│ ├── models
│ │ └── models.go
│ └── pkg
│ ├── endpoints
│ │ └── endpoints.go
│ ├── handlers
│ │ └── handlers.go
│ ├── repositories
│ │ └── repositories.go
│ └── service
│ ├── cities.go
│ └── service.go
├── go.mod
├── go.sum
├── LICENSE
├── main.go
├── README.md
└── weather-information-system.sql
8 directories, 13 files