Here is a README.md for using the API based on your instructions:
This API allows you to get and post weather data to a PostgreSQL database.
Before using this API, ensure you have the following installed:
- Go: Download Go
- Docker: Install Docker
Follow the steps below to get started with the API:
Clone the repository to your local machine:
git clone https://github.com/bunnybunbun37204/arch-weather-server.git
cd weather-apiYou need to create a .env file to store environment variables. You can get the .env file from my Discord.
After setting up the .env file, install the necessary Go libraries:
go mod tidy- Build and run the Docker containers:
docker-compose up- Start the server by running the following Go command:
go run cmd/server/main.goThe server will start on http://localhost:8080.
This endpoint retrieves the latest weather value from the database.
Response Format:
{
"ID": 1,
"CreatedAt": "0001-01-01T00:00:00Z",
"Pressure": 1013.25,
"RelativeHumidity": 85,
"Temperature": 30.5,
"WindDirection": 90,
"WindSpeed": 5,
"CHP1": 1.2,
"DirectSun": 400,
"GlobalSun": 800,
"DiffuseSun": 200,
"RainFall": 10.5,
"AllDayIllumination": 1200,
"PM25": 15
}This endpoint allows you to post new weather data to the database.
Request Body Format:
{
"Pressure": 1013.25,
"RelativeHumidity": 85,
"Temperature": 30.5,
"WindDirection": 90,
"WindSpeed": 5,
"CHP1": 1.2,
"DirectSun": 400,
"GlobalSun": 800,
"DiffuseSun": 200,
"RainFall": 10.5,
"AllDayIllumination": 1200,
"PM25": 15
}Example POST Request (Using curl):
curl -X POST http://localhost:8080/weather \
-H "Content-Type: application/json" \
-d '{
"Pressure": 1013.25,
"RelativeHumidity": 85,
"Temperature": 30.5,
"WindDirection": 90,
"WindSpeed": 5,
"CHP1": 1.2,
"DirectSun": 400,
"GlobalSun": 800,
"DiffuseSun": 200,
"RainFall": 10.5,
"AllDayIllumination": 1200,
"PM25": 15
}'- If you encounter issues with Docker, ensure that Docker is properly installed and running.
- If you have issues with Go dependencies, make sure you have the correct versions of Go installed.
This project is licensed under the MIT License - see the LICENSE file for details.
### Key Sections:
1. **Prerequisites**: Instructions for installing Go and Docker.
2. **Setup**: Instructions for setting up the environment, creating the `.env` file, and running the server.
3. **API Documentation**: Descriptions of the `GET /weather` and `POST /weather` endpoints, with the respective response and request formats.
4. **Troubleshooting**: Provides basic troubleshooting information in case the user encounters issues.