docker compose up --build -d
docker compose down
When completed access the Redis UI:
(Accept Terms the first time, could probably be avoided with some config passed to the Docker container)
For development it is possible to run the docker compose that is just starting Redis
docker compose -f docker-compose-development.yml up --build -d
To run:
go run main.go
2023/06/30 09:56:27 Starting
2023/06/30 09:56:27 Redis host localhost:6379
2023/06/30 09:56:27 Port file ../data/ports.json
2023/06/30 09:56:27 Added 1632 Took 799.934125ms
docker compose down
go test ./...
At the moment there are only few tests for demonstration.
Coverage can be checked with:
go test ./... -cover
In a real repo there may be a check on minimum coverage.
Unit tests:
Functional test (sort of):
Apart from the tests in the repo there will be end to end tests involving real external resources (DBs, third party services...).
- Add constructor with validation for
PortData
PortData.Coordinates
could be a specific struct with lat, lon and validation- Mock Redis and Postgres to be able to create tests
- Add more tests and maybe a check on the coverage
- Now the service that is injesting to the DB exits immediately, with more time an API (gRPC, REST) could have been added
- Better naming and spend more time on the code structure to fit with Hexagonal patterns
- Generated a file with 100k random ports, that took ~30s to add to the DB.
In case of large files (although I think the data would probably be on another DB) it might be worth investigating if it is possible to split the file and upload to the DB in parallel. - Redis was chosen for simplicity but depending on the access patterns (maybe a query by Country) another DB might be more appropriate.
- When tested with Redis the
SavePort
function was also updating if item already present