Restaurant menu voting and management REST api service implemented on golang.
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
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.
- 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
- Install Docker on your local machine - Get Docker
- Install and setup golang. v 1.14 required - golang Gettins Started
- Git Getting Started - Install Git
- Install Gnu make (optional) - makes life a little bit simpler.
- 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.
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.
You can use git clone to clone this repository to your computer.
git clone https://github.com/remisb/mat.git
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.
TBD If you are having problems installing docker reach out or jump on Gopher Slack
for help.
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
A makefile has also been provide to allow building, running and testing the software easier.
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
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.
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.
make up
- starts docker compose containers used for developmentmake down
-make migrate
- Migrate attempts to bring the schema for db up to date with the migrationsmake seed
- Seed runs the set of seed-data queries against db. The queries are ran in a transaction and rolled back if any fail.
- Docker container
- PostgreSql
- viper - Go configuration with fangs
- Go-chi - lightweight, idiomatic and composable router for building Go HTTP services
- Go-chi - JWT authentication middleware for Go HTTP services
- [uber zap logger - Blazing fast, structured, leveled logging in Go](Uber Zap logger)
- GNU Make
- httpexpect - End-to-end HTTP and REST API testing for Go.
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
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.
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
- 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
- 1 dfaslkdf
- 2 sadkfjasd;lkf
REST API service based on Chi Routes and mix of solutions from Mat Ryer book Go Programming Blueprints and ardanlabs service repository.
References to:
- Mat Rayer
- go-chi router
- ardanlabs service
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)