The application retrieve data about pharmacies in Campania (Italy) on startup from an exposed list provided by Regione Campania.
Data about pharmacies is refreshed every 24 hours and persisted in memory.
- Docker
- Build the container
docker build --tag jsonrpc .
- Start the container
docker run --rm -p 8080:8080 --name jsonrpc jsonrpc:latest
Application will be started on port 8080
inside the docker container. To change the port binding on your host simply change the first port in the docker run command.
For example to use port 9901
you can use this command:
docker run --rm -p 9901:8080 --name jsonrpc jsonrpc:latest
Image Size:
REPOSITORY TAG IMAGE ID CREATED SIZE
jsonrpc latest <> 25 seconds ago 7.33MB
jsonrpctest latest <> 15 hours ago 546MB
Docker container is built with multi-stage build to achieve a really small size of only 7.33MB.
Test execution can be done on your local machine or in a Docker container (without installing anything else, beside of Docker).
- Unit Test
make test
- Integration Test
make integration
Test coverage
go test --cover ./...
Full test (Unit + Integration):
docker build --tag jsonrpctest . -f test.dockerfile
docker run --rm jsonrpctest:latest
The JSON RPC server and the Pharmacy.SearchNearestPharmacy
method is exposed on the path /api
.
So using port 8080
the endpoint will be http://localhost:8080/api
.
curl --location --request POST 'http://localhost:8080/api' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": 1,
"jsonrpc": "2.0",
"method": "Pharmacy.SearchNearestPharmacy",
"params": [{
"currentLocation": {
"latitude": 41.10938993,
"longitude": 15.0321010
},
"range": 10000,
"limit": 6
}]
}'
The application structure is inspired by the Standard Go Project Layout
.
├── adapter
│ └── web
├── cmd
│ └── jsonrpc
├── config
├── datalayer
│ ├── memory
├── internal
│ ├── coordinates
│ └── rpcserver
├── model
├── presentation
│ └── jsonrpc
- adapter contains the logic for external services comunication. An example is the logic to retrieve pharmacies list from the external source.
- cmd contains all the entrypoint of the application divided by directory
- config contains all the configuration files template or the default configs
- datalayer contains all the logic to retrieve data from data sources. The actually data source is abstracted with an interface.
- internal contains the unexported logic
- model contains all the definitions of the entity involved
- presentation containes all the logic and the abstraction to expose information on differents channels (RPC, REST, GRPC, ...)