Coder Social home page Coder Social logo

rameshsunkara / go-rest-api-example Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 14.0 228 KB

Enterprise ready REST API microservice in golang

License: MIT License

Dockerfile 0.45% Makefile 3.82% Go 95.73%
boilerplate golang docker-compose mongodb example-app go golangci-lint owasp api api-framework api-rest enterpriseservices rest-apis sample-app

go-rest-api-example's Introduction

Build Status Go Report Card codecov

REST API microservice in Go

Offered Features

API Features:

  1. OWASP Compliant Open API 3 Specification: Refer to OpenApi-v1.yaml for details.
  2. Middleware for:
    • Logging: Facilitates debugging and monitoring processes.
    • Authentication: Provides a placeholder for diverse authentication mechanisms.
    • Tracing by Request ID: Assists in debugging procedures.
    • Panic Recovery: Ensures service continuity by managing unexpected errors.
    • Common Security Headers: Safeguards the service against potential vulnerabilities.
    • Query Parameters Validation: Enhances service security by validating query parameters.
  3. Standardized Error Handling: All errors are managed and returned in a uniform format.
  4. Versioning
  5. Model Management:
    • Internally used data models differ from those exposed to clients, ensuring separation and security.

Go Application Features:

  1. Configuration Management: via Environment Variables
  2. Dockerized Environment: Facilitates service deployment.
  3. Makefile: Automates common tasks for developers.
  4. Git Action: Automates build processes, runs tests, and generates code coverage.
  5. Integrated Go Formatter and Linter: Promotes code quality and consistency.
  6. Secrets Loading Mechanism from Sidecar
  7. Support for Multiple Databases: Enables connections to various database systems.
  8. Best Practices for MongoDB Connection
  9. Effective Mocking Practices for Unit Test Patterns
  10. Seed Data: for Local Development
  11. Standardized Filename Conventions: Enhances code readability.
  12. Multi-Stage Docker Build: Accelerates build processes.
  13. Versioning Utilizing Git Commit History

Folder Structure

go-rest-api-example/
├── main.go
├── internal/
│   ├── db
│   ├── errors
│   ├── handlers
│   ├── logger
│   ├── middleware
│   ├── models
│   ├── server
│   ├── util
│   └── mockData
├── localDevelopment/
├── Makefile
├── Dockerfile
├── OpenApi-vi.yaml
├── docker-compose.yaml
└── OpenApi-v1.postman_collection.json

QuickStart

Pre-requisites: Docker, Docker Compose, Make

  1. Start the service

     make start
    

Other Options:

Choose a command to run in go-rest-api-example:

  start                         Starts everything that is required to serve the APIs
  run                           Run the API server alone (without supplementary services such as DB etc.,)
  build                         Build the API server binary
  version                       Display the current version of the API server
  test                          Run tests
  coverage                      Measures and generate code coverage report
  tidy                          Tidy go modules
  format                        Format go code
  lint                          Run linter
  lint-fix                      Run linter and fix the issues
  docker-build                  Build the API server as a docker image
  docker-run                    Run the API server as a docker container
  docker-start                  Builds Docker image and runs it.
  docker-stop                   Stops the docker container
  docker-remove                 Removes the docker images and containers        
  docker-clean                  Cleans all docker resources
  docker-clean-service-images   Stops and Removes the service images
  docker-clean-build-images     Removes build images
  owasp-report                  Generate OWASP report
  go-work                       Generate the go work file

Tools

  1. Routing - Gin
  2. Logging - zerolog
  3. Database - MongoDB
  4. Container - Docker

TODO

  • Add more and clear documentation about the features this offers and how to replace tools
  • Add DB Migration Support
  • Add more environmental profiles and obey all 12-Factor App rules
  • Implement all OWASP security checks specified in the API Spec
  • Improve error codes and messages
  • Add git hooks for pre-commit and pre-push

Good to have

  • Improve data model and add more fields
  • Deploy to cloud
  • Implement Update Operations mentioned in the API Spec

References

Contribute

  • Please feel free to Open PRs
  • Please create issues with any problem you noticed
  • Please suggest any improvements

Why this ?

I embarked on the endeavor of crafting my own open-source boilerplate repository for several reasons:

After years of developing Full Stack applications utilizing ReactJS and JVM-based languages, I observed that existing boilerplates tended to be either excessive or insufficient for my needs. Consequently, I resolved to construct my own, while adhering rigorously to the principles and guidelines of Go. While similarities with popular Go boilerplate templates may be evident, I have customized this repository to better align with my preferences and accumulated experiences. (My apologies if I inadvertently overlooked crediting any existing templates.)

I yearned for the autonomy to meticulously select the tools for fundamental functionalities such as Routing, Logging, and Configuration Management, ensuring seamless alignment with my personal preferences and specific requirements.

What this is not ?

  • This isn't a complete solution for all your needs. It's more like a basic template to kickstart your project.
  • This isn't the best place to begin if you want to make an online store. What I've provided is just a simple tool for managing data through an API.

go-rest-api-example's People

Contributors

sunkarar avatar rameshsunkara avatar dependabot[bot] avatar

Stargazers

Prateek Gogia avatar Ido Widya Yudhatama avatar Corlys Verlaryon avatar Christopher Geary avatar Evsyukov Denis avatar Noah Whitney avatar Aadil Sayed avatar  avatar  avatar  avatar  avatar Hugo Pereira avatar  avatar Shujaat Ali Khan avatar Foo Shi Yu avatar Nicholas Mantovani avatar Thomas avatar Sean Aguirre avatar Renaud R. avatar Maher Zae avatar  avatar Rhayem Bannouri avatar Ronnie Flathers avatar Tejas Gajare avatar Vivek T S avatar Tuan Anh avatar Ramya Simhadri avatar karanveer avatar  avatar Rob Wilburn avatar Allan Martinez avatar Tsung-Han Ho avatar anothersesar avatar Lucas Aguiar avatar  avatar Tolu Adesina avatar Mykyta Kravchenko avatar Robin Venneman avatar Annisaseptriyana avatar  avatar  avatar  avatar João Pedro avatar Xun Zhou avatar AravindhKm avatar Caesario Dito avatar Benzer avatar Julian Popov avatar Sreehari Jayaraj avatar Harish Durga avatar Mir Arif Hasan avatar Sohel Mia avatar  avatar mrqwertyuiop avatar PHolcik avatar Ergildo Dias avatar Emre Alkan avatar Tarek Abdelhamid avatar  avatar  avatar  avatar  avatar Mark Vilrokx avatar

Watchers

James Cloos avatar  avatar Scott Russell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.