Skip to content

archit-p/MicroserviceTemplate

Repository files navigation

Build Status Go Report Card Codacy Badge Quality Gate Status Coverage
Go Microservice built using best practices, ideal for use as a starter template. It features an extensible model - Sample - with support for CRUD and Search operations for MongoDB.

References

This project is inspired by multiple blogs and guides on best practices while writing Go code. I'm sharing links to these below.

Project Structure

  1. How to Write Go Code
  2. golang-standards/project-layout
  3. Organizing Database Access

Documentation

  1. Documenting APIs with Swagger
  2. Documenting Go Code

Containerization

  1. Docker: Multi-Stage Builds
  2. Why You Should Use Microservices and Containers

Testing

  1. Structuring Tests in Go
  2. Testing Web-Apps in Go

Getting Started

Clone the Repo

$ git clone https://github.com/archit-p/MicroserviceTemplate

Build and Run

$ 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

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)

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!

Built Using

Golang MongoDB Docker