REST API that allows clients to communicate with * (i.e. dispatch controller).
NOTE: Drones app has been tested on Ubuntu 18.04 and on Windows 10 with WSL and Golang 1.18 was used.
The GitHub Template API server provides the following Example API with communicating the DB:
Tag | Title | URL | Query | Method |
---|---|---|---|---|
Auth | user authentication (Using JWT) | /api/v1/auth |
- | POST |
Auth | user logout | /api/v1/auth/logout |
- | GET |
Auth | get user authenticated | /api/v1/auth/user |
- | GET |
Database | Populate DB with fake data | /api/v1/database/populate |
- | POST |
Drones | Get all drones or filters for State | /api/v1/drones |
?state= | GET |
Drones | Registers or update a drone | /api/v1/drones |
- | POST |
Drones | Get a drone by serialNumber | /api/v1/drones/:serialNumber |
- | GET |
Medications | Get medications | /api/v1/medications |
- | GET |
Medications | Checking loaded items for a drone | /api/v1/medications/items/:serialNumber |
- | GET |
Medications | Load a drone with medication items | /api/v1/medications/items/:serialNumber |
- | POST |
To see the API specifications in more detail, run the app and visit the swagger docs:
Param | Description | default value |
---|---|---|
APIDocIP | IP to expose the api (unused) | 127.0.0.1 |
DappPort | app PORT | 7001 |
StoreDBPath | DB file location | ./db/data.db |
CronEnabled | active the cron job | true |
LogDBPath | DB file event logs | ./db/event_log.db |
EveryTime | time interval (in seconds) that the cron task is executed | 300 seconds (every 5 minutes) |
By default, StoreDBPath generates the database file in the /db folder at the root of the project.
The server exposes the /api/v1/database/populate
POST endpoint to generate and repopulate the database whenever necessary.
Download the github.template-srv.restapi.iris-go project and move to root of project:
git clone https://github.com/kmilodenisglez/github.template-srv.restapi.iris-go.git && cd github.template-srv.restapi.iris-go
You can start the server in 2 ways, the first is using docker and docker-compose and the second is manually
You will need docker and docker-compose in your system.
To builds Docker image from Dockerfile, run:
docker build --no-cache --force-rm --tag app_restapi .
Use docker-compose to start the container:
docker-compose up
Run:
go mod download
go mod vendor
If you make changes to the Endpoint you must generate Swagger API Spec:
Build:
go build
The environment variable is exported with the location of the server configuration file.
If you have 🐧Linux or 🍎Dash, run:
export SERVER_CONFIG=$PWD/conf/conf.yaml
but if it is in the windows cmd, then run:
set SERVER_CONFIG=%cd%/conf/conf.yaml
Before it is recommended that you read more about the server configuration file in the section 👉🏾 .
Run the server:
./restapi.app
and visit the swagger docs:
The first endpoint to execute must be /api/v1/database/populate [POST], to populate the database. That endpoint does not need authentication.
You can then authenticate and test the remaining endpoints.
Run:
go test -v
This project has 3 layer :
- Controller Layer (Presentation)
- Service Layer (Business)
- Repository Layer (Persistence)
Tag | Path | Layer |
---|---|---|
Auth | end_auth.go | Controller |
Drones | end_drones.go | Controller |
EventLog | end_eventlog.go | Controller |
Auth | svc_authentication.go | Service |
Drones | svc_drones.go | Service |
EventLog | svc_eventlog.go | Service |
Auth | repo_drones.go | Repository |
Drones | repo_drones.go | Repository |
EventLog | repo_eventlog.go | Repository |