![MongoDB](https://www.vectorlogo.zone/logos/mongodb/mongodb-ar21.svg)
![Go Report Card](https://goreportcard.com/badge/github.com/archit-p/go-microservice)
Go Microservice built using best practices, ideal for use as a starter template. It features an extensible model - Sample - with support for CRUD operations for MongoDB.
References
The idea for this project came up after reading multiple blogs and guides on best practices while writing Go code. I'm sharing links to these below.
Project Structure
- How to Write Go Code
- golang-standards/project-layout
- Organizing Database Access
Documentation
- Documenting APIs with Swagger
- Documenting Go Code
Containerization
- Docker: Multi-Stage Builds
- Why You Should Use Microservices and Containers
Testing
- Structuring Tests in Go
- Testing Web-Apps in Go
Project Layout
cmd (contains code for our apps)
|-+ web (server router and controllers)
pkg (contains reusable code)
|-+ dto (data-transfer objects)
|-+ models (database models)
|-+ mongodb (models for mongo-db)
|-+ docs (swagger documentation)
Running
The project ships with a Makefile to build and run the service.
> make help
Run make <target> where target is
help: print out this message
build: build the executables
run: start a clean build, and run executable
test: run go tests
docs: build documentation
clean: clean executables and docs
> make run
Docs
Once the service is running, accompanying Swagger docs can be found at http://localhost:8080/swagger/index.html
.
Contributing
Feel free to fork the project for use as a base template for your next microservice or REST API!