Git Product home page Git Product logo

todo-backend's Introduction

To-do Backend

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

Getting Started

  1. Install Go >= 1.17 by following the instructions here.

  2. Install PostgreSQL >= 12 by following the instructions here.

  3. 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 leave DB_USER and DB_PASSWORD empty. This can be done by setting the DB_HOST to the following locations:

    • Linux: /var/run/postgresql
    • macOS: /tmp

    Note that if you are connecting via localhost, you might need to set DB_SSLMODE=disable.

  4. Create the database.

    $ make createdb
  5. Migrate the database.

    $ make migratedb
  6. Start the server. By default, the backend is accessible at http://localhost:8000/.

    $ make run

Linting

  1. Install golangci-lint by following the instructions here.
  2. 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 and make 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.

Running Tests

  1. 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.
  2. Create the test database.
    $ make createtestdb
  3. Migrate the test database.
    $ make migratetestdb
  4. Run the tests.
    $ make test

Deployment

Deployment makes use of the Serverless Framework. To deploy to AWS Lambda manually:

  1. Install Node >= 14 by following the instructions here.
  2. Install the Serverless Framework:
    $ npm install -g serverless
  3. 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
  4. Export the environment variables (see any of the .env.* files) for the database connection that will be used by the AWS Lambda function.
  5. 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
  6. Deploy the server.
    $ serverless deploy

todo-backend's People

Contributors

ianyong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.