danielkurniadi / benjerry-api

Ben & Jerry REST (CRUD) API written in Go
MIT License
2 stars 0 forks source link
crud-api golang mongodb rest-api

Ben & Jerry REST API

Building an API for Ben & Jerry's (ice cream) fans.

Changelog

Overviews

The following are the content of this docs.

  1. This README - Overview of this project
    1. Overviews
    2. Quick Setup and Run
  2. API Schema - Sample Requests and Response schema
  3. Design Docs - Software architecture documentation

Description

This is an example of implementation of Clean Architecture in Go (Golang) projects.

Rule of Clean Architecture by Uncle Bob

This project has 4 Domain layer. More at https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html

golang clean architecture

What features are included in example?

Dependencies

Quick Setup and Run

Make sure you have Go installed in your machine.

Since the project already use Go Module, I recommend to put the source code in any folder but $GOPATH.

Run Tests

The tests cover almost all the service, but some functionalities in common and repository layers are yet to be tested.

$ make test

Run the Applications

We provide two ways to deploy the application: using baremetal and using docker-compose.

Running on Unix/Linux based machine

Here is the steps to get it running in local machine. The requirement for running in linux are golang installed, mongodb (started and running at localhost:27017), and redis (started and running at localhost:6379).

  1. Prepare your and source the .env file. This contains environment variables to configure the application, e.g. define URI for database/redis. See example .env file provided along with this project.
# sample envvars for app configurations
export ENV_MODE=development
export DB_URI=mongodb://localhost:27017/tutorialDB
export REDIS_URI=redis://localhost:6379
  1. Build the binary file and run The application will run at localhost:8080 by default.
    make app-run

Running from Docker Compose

Here is the steps to run it with docker-compose.

#move to directory
$ cd workspace

# Clone into YOUR $GOPATH/src
$ git clone https://github.com/iqdf/benjerry-api.git benjerry

# move to project
$ cd benjerry

# To build the docker image first
$ make docker-build

# To run the application using docker compose
$ make compose-run

# To check that containers are running
$ docker ps -a

# To stop docker compose that ran the app
$ make compose-stop

TO DO Work and Features

Tools Used:

In this project, I use some tools listed below. But you can use any simmilar library that have the same purposes. But, well, different library will have different implementation type. Just be creative and use anything that you really need.