# Sensor Metadata API
The Sensor Metadata API is a JSON REST API that allows storing and querying sensor metadata. It provides endpoints for creating, retrieving, updating, and querying sensor metadata.
## Features
- Store sensor metadata including name, location (GPS position), and tags.
- Retrieve sensor metadata by name.
- Update sensor metadata.
- Find the nearest sensor based on a given location.
## Technologies Used
- Go programming language
- PostgreSQL database
- Gorilla Mux (HTTP router)
- pq (PostgreSQL driver)
- Docker (optional)
## Prerequisites
- Go 1.16 or higher installed
- PostgreSQL database running
## Getting Started
1. Clone the repository:
```bash
git clone https://github.com/your-username/sensor-metadata-api.git
cd sensor-metadata-api
- Set up the database:
- Create a PostgreSQL database.
- Update the database connection string in
main.go
with your database details.
- Build and run the application:
go build
./sensor-metadata-api
- The API server should now be running at
http://localhost:8080
.
URL: /sensors
Method: POST
Request Body:
{
"name": "Sensor1",
"location": {
"latitude": 123.456,
"longitude": 789.012
},
"tags": ["tag1", "tag2"]
}
Response:
- Status Code:
201 Created
- Response Body: Empty
URL: /sensors?name={name}
Method: GET
Response:
- Status Code:
200 OK
- Response Body:
{
"id": 1,
"name": "Sensor1",
"location": {
"latitude": 123.456,
"longitude": 789.012
},
"tags": ["tag1", "tag2"]
}
URL: /sensors/{name}
Method: PUT
Request Body:
{
"name": "Sensor1",
"location": {
"latitude": 111.222,
"longitude": 333.444
},
"tags": ["tag3", "tag4"]
}
Response:
- Status Code:
200 OK
- Response Body: Empty
URL: /sensors/nearest?latitude={latitude}&longitude={longitude}
Method: GET
Response:
- Status Code:
200 OK
- Response Body:
{
"id": 2,
"name": "Sensor2",
"location": {
"latitude": 222.333,
"longitude": 444.555
},
"tags": ["tag5", "tag6"]
}
To run the tests, use the following command:
go test ./...
You can also run the application using Docker. Dockerize the application with the following steps:
- Build the Docker image:
docker build -t sensor-metadata-api .
- Run the Docker container:
docker run -p 8080:8080 sensor-metadata-api
Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to submit a pull request.
Before contributing, please ensure that you:
- Follow the existing coding style and conventions.
- Write clear commit messages.
- Test your changes thoroughly.
This project is licensed under the MIT License. See the LICENSE file for details.
The Sensor Metadata API is built using various open-source libraries and frameworks. We would like to acknowledge and thank the following:
- Gorilla Mux - HTTP router for Go.
- pq - PostgreSQL driver for Go.
- Docker - Containerization platform.
For any inquiries or questions, please contact:
Sunil Kartikey Email: s.kartikey@gmail.com