Rest API for todoapp written in Golang, using clean architecture, CI/CD

Overview

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>='
   
    '
   

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 [email protected]
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
You might also like...
Apibuildr - Tool to generate REST apis in golang

ApiBuildr apibuildr is a commandline tool for creating rest apis in golang langu

How to get a Go / Golang app using the Gin web framework running natively on Windows Azure App Service WITHOUT using a Docker container

Go on Azure App Service View the running app - https://go-azure-appservice.azurewebsites.net 😎 This is an example repo of how to get a Go / Golang a

Book-API was made using Golang and PostgreSQL with technique CRUD with mux and pq

Book-API CRUD with PostgreSQL Table of contents 👀 General info Technologies Blog Setup General info BAPI or Book-API is a Golang REST API made to sho

library for working with github api, written in Golang

gitdata library for working with github api, written in Golang Example: get user data package main import ( "fmt" "log" "github.com/a1excoder/git

MongoDB generic REST server in Go
MongoDB generic REST server in Go

Mora - Mongo Rest API REST server for accessing MongoDB documents and meta data Documents When querying on collections those parameters are available:

Stop using install.sh! Start using install.yml! DAJE...

Daje - A general purpose Ansible dotfiles installer Configure one time and run everywhere. What is this I've never liked using a big bash script to in

Provides an interactive prompt to connect to ECS Containers using the ECS ExecuteCommand API.
Provides an interactive prompt to connect to ECS Containers using the ECS ExecuteCommand API.

ecsgo Heavily inspired by incredibly useful gossm, this tool makes use of the new ECS ExecuteCommand API to connect to running ECS tasks. It provides

A Teardown API to Lua stub generator written in Go.

Teardown API Stub Generator This project aims to provide a parser for the XML files at https://www.teardowngame.com/modding/api.xml These files descri

Kubernetes OS Server - Kubernetes Extension API server exposing OS configuration like sysctl via Kubernetes API

KOSS is a Extension API Server which exposes OS properties and functionality using Kubernetes API, so it can be accessed using e.g. kubectl. At the moment this is highly experimental and only managing sysctl is supported. To make things actually usable, you must run KOSS binary as root on the machine you will be managing.

Owner
Đạo Phạm
Đạo Phạm
Go-Mongodb API - A sample REST API ( CRUD operations ) created using Golang

Go-Mongodb_API This is a sample REST API ( CRUD operations ) created using the G

Aman Sharma 1 May 31, 2022
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.

marvel-universe-web using the Golang search the Marvel Universe Characters About The Project This project is a web based golang application that shows

Burak KÖSE 2 Oct 10, 2021
Golang Rest Api Sample

Golang Rest Api Sample Şimdi localhost’umuzda HTTP requestleri ile çalışan basit

Furkan Türkyılmaz 3 Nov 9, 2022
Reworking kube-proxy's architecture

Kubernetes Proxy NG The Kubernetes Proxy NG a new design of kube-proxy aimed at allowing Kubernetes business logic to evolve with minimal to no impact

Kubernetes SIGs 185 Jan 3, 2023
Service Discovery and Governance Center for Distributed and Microservice Architecture

Polaris: Service Discovery and Governance English | 简体中文 README: Introduction Components Getting started Chat group Contribution Visit website to lear

Polarismesh 1.8k Dec 31, 2022
Lightweight, single-binary Backup Repository client. Part of E2E Backup Architecture designed by RiotKit

Backup Maker Tiny backup client packed in a single binary. Interacts with a Backup Repository server to store files, uses GPG to secure your backups e

RiotKit 1 Apr 4, 2022
A seed repository that contains a Go project that accepts input via a REST API and saves data to an Oracle database.

rest-oracle-go-seed A seed repository that contains a Go project that accepts input via a REST API and saves data to an Oracle database. Why Oracle? T

Stephen 2 Apr 18, 2022
Koios-rest-go-client - Go Client library for Koios API

Koios API Client Library for Go Koios API is Elastic Cardano Query Layer! A cons

howijd.network 6 Mar 18, 2022
Go WhatsApp Multi-Device Implementation in REST API with Multi-Session/Account Support

Go WhatsApp Multi-Device Implementation in REST API This repository contains example of implementation go.mau.fi/whatsmeow package with Multi-Session/

Dimas Restu H 62 Dec 3, 2022
cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API.

Overview cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resou

Daimler Group 61 Oct 27, 2022