Created for CS3219 Software Engineering Principles and Patterns Own Time Own Target (OTOT) Task B. Makes use of the Ports & Adapters architecture.
Frontend: https://github.com/ianyong/todo-frontend
-
Install Go
>= 1.17
by following the instructions here. -
Install PostgreSQL
>= 12
by following the instructions here. -
Make a copy of
.env.development
as.env.development.local
. For development on your local system, it is recommended that you connect to PostgreSQL via Unix-domain sockets so that there is no need for database server credentials, allowing you to leaveDB_USER
andDB_PASSWORD
empty. This can be done by setting theDB_HOST
to the following locations:- Linux:
/var/run/postgresql
- macOS:
/tmp
Note that if you are connecting via
localhost
, you might need to setDB_SSLMODE=disable
. - Linux:
-
Create the database.
$ make createdb
-
Migrate the database.
$ make migratedb
-
Start the server. By default, the backend is accessible at http://localhost:8000/.
$ make run
- Install
golangci-lint
by following the instructions here. - Optionally, you can integrate the linter with your IDE if it is supported by following the instructions here.
Otherwise, you will need to run
make fmt
andmake lintfix
to automatically format and fix any lint violations before you commit any changes, or add a pre-commit Git hook that does it for you automatically.
Note that gosec
is a supported linter in golangci-lint
.
As such, there is no need to separately install gosec
for local development.
- Make a copy of
.env.test
as.env.test.local
. The configuration should be similar to.env.development.local
as described above, but with a different database name. - Create the test database.
$ make createtestdb
- Migrate the test database.
$ make migratetestdb
- Run the tests.
$ make test
Deployment makes use of the Serverless Framework. To deploy to AWS Lambda manually:
- Install Node
>= 14
by following the instructions here. - Install the Serverless Framework:
$ npm install -g serverless
- Build the server for use with AWS Lambda.
Note that the normal server has to be wrapped with a translation layer so that the server is able to understand API requests and responses that go through AWS Lambda.
$ make buildlambda
- Export the environment variables (see any of the
.env.*
files) for the database connection that will be used by the AWS Lambda function. - Migrate the database that will be used.
Make sure that the correct environment variables are loaded from the step before.
$ GO_ENV=production make migratedb
- Deploy the server.
$ serverless deploy