This is a simple system that processes user locations and provides the ability to search for clients by location (coordinates) and radius, with an additional functionality of calculating the distance traveled by a user in a given time range.
- Clone the repository
git clone github.com/surtexx/locsearch
- Install the dependencies
go mod download
- Create a
.env
file in the root of the project and add the following environment variables:
LOCATIONS_TABLE=<YOUR_DYNAMODB_LOCATION_TABLE>
LOCATION_HISTORY_TABLE=<YOUR_DYNAMODB_LOCATION_HISTORY_TABLE>
- Source the
.env
file
source .env
- Save AWS credentials in the
~/.aws/credentials
file
[default]
aws_access_key_id = <YOUR_AWS_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_AWS_SECRET_ACCESS_KEY>
- (Optional) Save AWS configuration in the
~/.aws/config
file
[default]
region = <YOUR_AWS_REGION>
output = json
- Run the application
go run cmd/locsearch/main.go
- Unit testing The application has unit tests saved in the same folder with the components they test. To run the tests, execute the following command:
go test ./...
- Integration testing The application has integration tests saved in same folder with the components they test. To run the tests, execute the following command:
go test ./... -tags=integration
The application has a REST API that can be accessed via the following endpoints:
PUT /updateLocation
- Update a user locationGET /searchUsers
- Get all users at a given location within a given radiusGET /getDistanceTraveled
- Get total distance travelled by a user in a time range
- Update a user location
curl -X PUT \
http://localhost:8080/updateLocation\?username\=rgheorghe\&newLocation\=39.13355,27.14538
- Search for users at a given location within a given radius
curl -X GET \
http://localhost:8080/searchUsers\?coordinates\=39.13355,29.14538\&radius\=100
- Get total distance traveled by a user in a time range
curl -X GET \
http://localhost:8080/getDistanceTraveled\?username\=rgheorghe\&startDate\=2023-01-01T00:00:00+00:00\&endDate\=2024-12-30T00:00:00+00:00
- Build the Docker image
docker build -t locsearch --build-arg LOCATIONS_TABLE=<YOUR_LOCATIONS_TABLE> --build-arg LOCATION_HISTORY_TABLE=<YOUR_LOCATION_HISTORY_TABLE> .
- Run the Docker container
docker run -p 8080:8080 locsearch
- Create the service and deployment
kubectl apply -f k8s
- Get the service DNS
kubectl describe svc/locsearch | grep "LoadBalancer Ingress:"
- Use the service DNS to access the application