- clone the repo
cd
at/periodic-task
directory- execute
make app.start ADDR=DesiredAddressHere PORT=DesiredPortHere
.
For examplemake app.start ADDR=0.0.0.0 PORT=8080
- If some or no arguments are given, the dockerfile is set to provide default values for the program to launch. The default SERVER_ADDRESS is
0.0.0.0
and the default "SERVER_PORT" is8000
The project is using Makefile, a docker-compose.yml (for expandability) and three dockerfiles for development, testing and production builds.
Using the endpoint bellow we can generate new timestamps.
GET - /ptlist
period
: REQUIRED
Is used to set the period (step) between the generated timestamps created from the periodic task.
Currently supporting values:
"1h" - for 1 hour, "1d" - for 1 day, "1mo" - for 1 month, "1y"- for 1 yeartz
: REQUIRED
Is used to set the timezone of the timestamps.
Accepted values:
A valid timezone. For example Europe/Athenst1
: REQUIRED
Is used to set the first timestamp (startDate) of the periodic task.
Accepted values:
A valid datetime timestamp. For example 20210214T204603Zt2
: REQUIRED
Is used to set the last timestamp (endDate) of the periodic task.
Accepted values:
A valid datetime timestamp. For example 20210215T204603Z
Please note that the addition of new periods is an extremely easy process. Some comments about it can be found here /internal/helper/timestamp_generator.go:52
Successful GET example
Request:
0.0.0.0:8080/ptlist?period=1mo&tz=Europe/Athens&t1=20210214T204603Z&t2=20211115T123456Z
Response:
[ "20210228T220000Z", "20210331T210000Z", "20210430T210000Z", "20210531T210000Z", "20210630T210000Z", "20210731T210000Z", "20210831T210000Z", "20210930T210000Z", "20211031T220000Z" ]
Failed GET example
Request:
0.0.0.0:8080/ptlist?tz=Europe/Athens&t1=20210214T200000Z&t2=20210219T200000Z
Response:
{ "status": "error", "desc": "invalid period parameter" }
make app.stop
:
This command actually runs "docker compose stop"make tests.generate-mock
:
This command takes as an input a .go file with an interface and generates a mock file for tests needs.make tests.tests-all
:
This command runs all the test files inside the project and provides a coverage number for each package.make tests.test-build
:
This command is used from make tests.tests-all in order to create a test build for the application (using dockerfile.test)
All the test cases given in the assessment can be found tested in timestamp_generator_test.go with good and bad paths.
TEST COVERAGE PERCENTAGES:
/internal/api coverage: 100.0% of statements
/internal/service coverage: 100.0% of statements
/internal/helper coverage: 100.0% of statements
Go-Delve has been set up for easy remote debugging. The default remote debugging port is 40000 (can change from the docker-compose.yml).
For example, if the server address is 0.0.0.0, then attach the remote debugger on the specified port like this 0.0.0.0:40000.