A simple go web api example applying clean architecure for working out Go
- As simple as possible
- Gin as dependency
- No surprise
- Extensible
Largely inspired by Mat Ryer videos on how he writes web API and Clean Architecture principles practices gathered along my career.
For demonstration purpose, the web API allows to found the nearest waste disposal near your home.
Note: for France only ;).
For this will use ADEME directory of waste disposal center web site service. ADEME is the French Ecological Transition Agency.
A OpenAPI definition is provided here api_docs.
- A client searching for the nearest waste disposal center send a request to
/waste-disposal/api/nearest
with its geo coordinates. The web api, first request to ADEME gateway necessary informations to compute the nearest center.
- WasteDisposalCenter
- GeoLocation
- FindNearest
- An adapter to ADEME API
make build
Will create an executable named server
in bin/ folder.
With Docker:
./scripts/build_image.sh
An image named goscawa
will be build.
make run
To test it:
curl localhost:8080?name=Dude
Tested with minikube.
Make you docker client point to run in minikube environment with:
eval $(minikube docker-env)
Build your image:
./scripts/build_image.sh
Deploy it:
minikube kubectl -- apply -f build/package/deployment.yaml