go-rest-service

module
v0.0.0-...-e10842c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: MIT

README

GO REST Service - Template

Build Status Go Report Card codecov

A simple Go REST service using:

  • Gin-gonic web framework
    • go get -u github.com/gin-gonic/gin
  • Goth for OAuth2 connections
    • go get github.com/markbates/goth
  • GORM as DB ORM
    • go get -u github.com/jinzhu/gorm
    • Gomigrate orm migrations
      • go get gopkg.in/gormigrate.v2
  • Migrate for migrations scripts
    • go get -u github.com/golang-migrate/migrate/v4
  • Zerolog for formatted logging
    • go get -u github.com/rs/zerolog

Development with locally

Clone the example.env file to .env and update the values for your local development. Run it locally with hot-reload:

sh scripts/run-air.sh

Run it locally without hot-reload:

sh scripts/run-dev.sh

Development with docker

Just run it with docker-compose:

docker-compose run dev

And you'll have the service for your development and testing.

Deployment

Use docker, swarm or kubernetes, GCP, AWS, DO, you name it.

Running prod.dockerfile will build a multistaged build that will give you a slim image containing just the service executable.

With docker-compose
docker-compose build prod

or

docker-compose run prod
Build from the prod.dockerfile
docker build -f docker/prod.dockerfile -t go-service.prod ./

Directories

Path Synopsis
cmd
service
Service command main package lets us start out service
Service command main package lets us start out service
internal
orm
Package orm provides `GORM` helpers for the creation, migration and access on the project's database
Package orm provides `GORM` helpers for the creation, migration and access on the project's database
pkg
auth
Package auth holds some standard auth functionalities.
Package auth holds some standard auth functionalities.
cfg
Package cfg is the configuration package hold all config objects
Package cfg is the configuration package hold all config objects
consts
Package consts all constants
Package consts all constants
env
Package env holds all environment variable related code
Package env holds all environment variable related code
logger
Package logger is an wrapper around the zerolog library
Package logger is an wrapper around the zerolog library
storage/dbm
Package dbm is a database management package.
Package dbm is a database management package.
storage/mongo
Package mongo to allow us to interact with NoSQL via MongoDB.
Package mongo to allow us to interact with NoSQL via MongoDB.
web
Package web is an wrapper around the net/http package to do basic http requests
Package web is an wrapper around the net/http package to do basic http requests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL