Skip to content
/ mat Public

REST API service based on Chi Routes and mix of solutions from Mat Ryer book Go Programming Blueprints and ardanlabs service repository.

Notifications You must be signed in to change notification settings

remisb/mat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mat

Go Report Card

Restaurant menu voting and management REST api service implemented on golang.

About

Company needs internal web service for its’ employees which helps them to make a decision on lunch place. Menus will be created each day and employees will vote for menu before leaving for lunch.

Requirements for implementation:

  • There should be a REST API for:
    • Authentication/registration (it can be assumed that only internal employees will have access to it)
    • Creating restaurant
    • Creating a menu for specific day
    • Getting current day menus
    • Voting for restaurant menu
    • Getting results for current day.
  • Reasonable amount of automated tests 
  • Solution should be uploaded to version control
  • Solution should be built using: GoLang, HTTP framework of your choice, database of your choice (either SQL or noSQL)
  • Sufficient logging must be implemented
  • Project README.md must be created with launch instructions

Solution for this assignment

I have reviewed what I have done on many of my previous solutions and decided to collect some of that experience in this one git repository. In addition to original reqirements I have few more in my mind. Here in this repository, I will try to figure out best, up to date my implementation of golang based web server.

Some extra requirements related with devops and architecture

  • Application is done to be fully configurable and to mach ["The Twelve-Factor App"] requirements. All application work related properties are externalized and app work can be configured with configuration file, CLI flags or environment apps.

TBD

Project setup / development and usage instructions

Features

  • HTTP routing and middleware support is provided with help of go-chi/chi router. As a bonus advantage chi router has wide set of core middlewares with additional auxiliary middlewares & packages.
  • Database support using Postgres.
  • CRUD based pattern.
  • Account signup and user management.
  • Testing patterns.
  • Use of Docker, Docker Compose, and Makefiles.
  • TBD - ntegration with CircleCI for enterprise-level CI/CD.

Requirement

This project contains two services and uses 3rd party services such as MongoDB and Zipkin. Docker is required to run this software on your local machine.

Downloading The Project

You can use git clone to clone this repository to your computer.

git clone https://github.com/remisb/mat.git

Installing Docker

Once the project is cloned, it is important to validate the installation. This project requires the use of Docker since images are created and run in a Docker-Compose environment.

Installing Docker

TBD If you are having problems installing docker reach out or jump on Gopher Slack for help.

Running Tests

With Docker installed, navigate to the root of the project and run the test suite.

NOTE - at the current time. Few tests are failing. Those failing test cases will be reviewed and updated. Nevertheless application is working correctly.

$ make test

Building And Running

A makefile has also been provide to allow building, running and testing the software easier.

Building The Project

Navigate to the root of the project and use the makefile to build all of the services.

$ cd $GOPATH/src/github.com/ardanlabs/service
$ make all

Running the project

Navigate to the root of the project and use the makefile to run all of the services.

$ cd mat
$ make up

The make up command will leverage Docker Compose to run all the services, including the 3rd party services. The first time you run this command, Docker will download the required images for the 3rd party services.

Default configuration is set for the developer environment which should be valid for most systems. Use the docker-compose.yaml file to configure the services differently if necessary.

Stopping the project

You can hit C in the terminal window running make up. Once that shutdown sequence is complete, it is important to run the make down command.

$ <ctrl>C
$ make down

Running make down will properly stop and terminate the Docker Compose session.

Provided make targets

  • make up- starts docker compose containers used for development
  • make down -
  • make migrate - Migrate attempts to bring the schema for db up to date with the migrations
  • make seed - Seed runs the set of seed-data queries against db. The queries are ran in a transaction and rolled back if any fail.

Project is based on the following tools, technologies and packages

Project consist two administration and management CLI executable files admin and rest-api. Source code of those executables is located in:

  • cmd/mat-admin - admin application
  • cmd/rest-api - restaurant REST-API microservice

How to setup and start development

Project uses PostgreSql database for data storage.

Project setup and common development task can be invoked through makefile targets. Bellow is provided a list of default makefile targets.

down                           Stops Docker containers and removes containers, networks, volumes, and images created by up.
keys                           Generate private key file to private.pem file
migrate                        Migrate attempts to bring the schema for db up to date with the migrations defined.
seed                           Seed runs the set of seed-data queries against db. The queries are ran in a transaction and rolled back if any fail.
up                             Builds, (re)creates, starts, and attaches to Docker containers for a service.

Database setup

Start PostgreSql docker container. All tasks are dependent on the postgreSql docker container, before performing any other task make up should be executed and DB container should accept incomming DB connections on the default PostgreSql port 5432.

> make up

To create default DB schema.

> make migrate

To fill database with default testing data.

> make seed

ToDo

  • Finish logging to external file
  • write documentation
  • write config file documentation
  • write CLI flag documentation
  • write ENV variable documentation
  • update / improve app flag documentation
  • add swagger documentation
  • extend / update makefile to improve development experience
  • review / cleanup / update makefile

Requirements

  • 1 dfaslkdf
  • 2 sadkfjasd;lkf

Background

REST API service based on Chi Routes and mix of solutions from Mat Ryer book Go Programming Blueprints and ardanlabs service repository.

References to:

Development tips

In case if db docker container is not cleaned up properly. That may happen in the test development process, you may have to stop and remove postgresql db container.

Bash shell

docker stop $(docker ps -aq)
docker rm $(docker ps -aq)

Fish shell

docker stop (docker ps -aq); docker rm (docker ps -aq)

About

REST API service based on Chi Routes and mix of solutions from Mat Ryer book Go Programming Blueprints and ardanlabs service repository.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages