Skip to content

Rest API for todoapp written in Golang, using clean architecture, CI/CD (including unit test and integration test).

Notifications You must be signed in to change notification settings

daopmdean/todoapp-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

todoapp-backend

Rest API for todoapp written in Golang, using Clean Architecture and CI/CD (includes unit tests and integration tests).

Using:

  • Web framework: Gin
  • Authentication: JWT
  • Database (choose one out of three options):
    • In Memory DB
    • Microsoft SQL Server (using Gorm)
    • MongoDB
  • CI/CD:
    • GitHub Actions (Docker Image for testing)
    • Microsoft Azure Web App (Docker Image for deployment)

Note: Config to change database (default to In Memory DB)

Getting Started

Development environment needed:

Clone the project to your working directory

git clone https://github.com/daopmdean/todoapp-backend.git

This project support to run on

  • Memory Database
  • Microsoft SQL Server Database
  • MongoDB

Setup env on zsh

export <ENV_NAME>='<ENV_VALUE>'

check to see if your environment declared

echo $<ENV_NAME>

Example

export NAME='Dean'
echo $NAME
-> Dean

PORT: environment variable to setup the port your program running on.
If you don't set PORT env variable, Program will run on default port: http://localhost:5000
Example:

export PORT=3456
Your program will run on -> http://localhost:3456

DB Mode

You can choose DB Mode to run with DB_MODE environment variable. If you do not provide any, default the program will run with memory db.

Memory DB

Run the program

make run

MS SQL DB

export DB_MODE=mssql

Using ORM Library: Gorm
Setup env variables

  • DB_USERNAME: Username to connect to sql server
  • DB_PASSWORD: Password to connect to sql server
  • DB_HOST: Host to connect to sql server
  • DB_PORT: Port to connect to sql server
  • DB_NAME: Database name to connect to sql server

Example

export DB_USERNAME=sa
export DB_PASSWORD=MyPassword@123
export DB_HOST=localhost
export DB_PORT=1433
export DB_NAME=todoapp

Run the program

make run

MongoDB

export DB_MODE=mongodb

Setup env variables

  • MONGO_URI: Connection string to MongoDB
  • MONGO_DB_NAME: Database name

Run init mongodb to create indexes

Note: this command should run only once when initialize MongoDB

make init_mongodb

Run the program

make run

Test

To run all tests

make test_all

To run api tests

make test_api

To run usecase tests

make test_usecase

To run entity tests

make test_entity

System Architect

The system designed following The Clean Architecture guideline.

Clean Architect

Project structure

todoapp
├── cmd/server
│   └── main.go
├── internal
│   └── adapter
│       └── http/rest
│       └── memdb
│       └── mssqldb
│       └── mongodb
│   └── common/config
│   └── entity
│   └── usecase
│       └── repo
└── test
    └── api_rest_test
    └── repomock

Annotate

  • cmd/server/main.go: run the program
  • adapter: store plugins that you can easily replace with another implementations
  • http/rest: store api handle http request with gin-gonic framework
  • memdb: implementations for memory db
  • mssqldb: implementations for microsoft sql server db
  • mongodb: implementations for mongodb
  • test: store test cases

About

Rest API for todoapp written in Golang, using clean architecture, CI/CD (including unit test and integration test).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages