README.md aktualisiert

This commit is contained in:
Simon Rieger 2023-11-24 13:57:21 +01:00
parent 62cbd281b0
commit 7679b06276

200
README.md
View file

@ -1,98 +1,102 @@
# Go Location Logger # Go Location Logger
A simple Go program that handles location data sent via HTTP POST requests and inserts it into a MySQL database. A simple Go program that handles location data sent via HTTP POST requests and inserts it into a MySQL database.
## Features ## Features
- Handles JSON payloads containing location data. - Handles JSON payloads containing location data.
- Inserts location data into a MySQL database. - Inserts location data into a MySQL database.
- Supports parameters `device` and `user` in HTTP requests. - Utilizes headers `X-Limit-U` and `X-Limit-D` for specifying user and device information in HTTP requests.
## Prerequisites ## Prerequisites
Before running the program, ensure you have the following: Before running the program, ensure you have the following:
- Go installed: [https://golang.org/doc/install](https://golang.org/doc/install) - Go installed: [https://golang.org/doc/install](https://golang.org/doc/install)
- Docker and Docker Compose installed: [https://docs.docker.com/get-docker/](https://docs.docker.com/get-docker/) - Docker and Docker Compose installed: [https://docs.docker.com/get-docker/](https://docs.docker.com/get-docker/)
## Installation ## Installation
1. Clone the repository: 1. Clone the repository:
```bash ```bash
git clone https://github.com/yourusername/go-location-logger.git git clone https://github.com/yourusername/go-location-logger.git
``` ```
2. Navigate to the project directory: 2. Navigate to the project directory:
```bash ```bash
cd go-location-logger cd go-location-logger
``` ```
3. Install dependencies: 3. Install dependencies:
```bash ```bash
go get -u github.com/sirupsen/logrus go get -u github.com/sirupsen/logrus
``` ```
4. Create an `.env` file in the project root with your environment variables: 4. Create an `.env` file in the project root with your environment variables:
```plaintext ```plaintext
# .env # .env
DB_USER=your_db_user DB_USER=your_db_user
DB_PASSWORD=your_db_password DB_PASSWORD=your_db_password
DB_HOST=your_db_host DB_HOST=your_db_host
DB_PORT=your_db_port DB_PORT=your_db_port
DB_NAME=your_db_name DB_NAME=your_db_name
``` ```
## Usage ## Usage
### Running with Docker Compose ### Running with Docker Compose
1. Create a Docker network: 1. Create a Docker network:
```bash ```bash
docker network create app-network docker network create app-network
``` ```
2. Use Docker Compose to start the services: 2. Use Docker Compose to start the services:
```bash ```bash
docker-compose up -d docker-compose up -d
``` ```
3. Access your Go application at `http://localhost:8080`. Make HTTP POST requests as described in the README.md. 3. Access your Go application at `http://localhost:8080`. Make HTTP POST requests as described in the README.md.
4. To stop the services, run: 4. To stop the services, run:
```bash ```bash
docker-compose down docker-compose down
``` ```
### Running without Docker ### Running without Docker
If you prefer not to use Docker, you can run the Go application directly using: If you prefer not to use Docker, you can run the Go application directly using:
```bash ```bash
go run main.go go run main.go
``` ```
The server will start on `http://localhost:8080`. The server will start on `http://localhost:8080`.
Make a POST request with a JSON payload to `http://localhost:8080/?device=your_device&user=your_user`. The JSON payload should include location data. Make a POST request with a JSON payload to `http://localhost:8080/?device=your_device&user=your_user`. The JSON payload should include location data.
Example: Example:
```bash ```bash
curl -X POST -d '{"_type": "location", "tst": 1637650367, "lat": 37.7749, "lon": -122.4194, "tid": "123", "batt": 90, "vac": 220}' http://localhost:8080/?device=your_device&user=your_user curl -X POST -H "Content-Type: application/json" \
``` -H "X-Limit-U: your_user" \
-H "X-Limit-D: your_device" \
## Contributing -d '{"_type": "location", "tst": 1637650367, "lat": 37.7749, "lon": -122.4194, "tid": "123", "batt": 90, "vac": 220}' \
http://localhost:8080/
Feel free to open issues or submit pull requests. ```
## License ## Contributing
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details. Feel free to open issues or submit pull requests.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.