Giter VIP home page Giter VIP logo

gin-template's Introduction

Gin Template

A simple gin RESTful API template with following function.

  • complete backend architecture
  • use gorm build data model
  • use logrus and other plugin to build logger service
  • user swagger to generate docs and mock test
  • simple user auth service with JWT
  • simple test framework
  • ci/cd example

Arch

--- pkg
 |------- common
 |------- controller
 |------- middleware
 |------- model
 |------- router
 |------- setting
  • common
    • put tool which use in other service, ex. jwt, logger, etc.
  • controller
    • accept input come from router
  • middleware
    • some middleware, ex. logger, auth, etc.
  • router
    • put all router here
  • setting
    • convert enviroment value to CONFIG struct here

Enviroment

All env this project use, you can change default value in here.

Name Description Value Type
APP_ADDRESS web app address 8080 string
APP_PORT web app port 0.0.0.0 string
DB_HOST DB host localhost string
DB_PORT DB port 5432 string
DB_NAME DB name gintemplate string
DB_USERNAME DB user name arashi87 string
DB_PASSWORD DB user password m3ow87 string
DB_TIMEZONE DB timezone Asia/Taipei string
JWT_EXPIRE JWT expire time (hours) 1 int
JWT_SECRET JWT secret arashi87 string
JWT_ISSUER JET issuer arashi87 string
LOG_PATH Log file save path /tmp/gin.log string
LOG_EXPIRE Log file expire time (hours) 720 int
LOG_ROTATE When should log file rotate (hours) 12 int

Logger

This project use logrus + rotatelogs + lfshook to build log service.

  • logrus use to instead of origin go logger
  • rotatelogs use to split log file periodically
  • lfshook is the logrus hook plugin, it will match log level to decide which log file should be write.

Test

Not implement yet.

CI/CD

Not implement yet.

Run

Name Version
Go go1.17.6
Make GNU Make 3.81
  1. Initialize environment variable
cp env-sample .env
  1. Start database
docker-compose up -d
  1. Build service

It will build swagger document in ./docs at the same time, and u will get a executable file named app.

make build
  1. Start service
./app
  1. Result

You should be able to accept service by http://localhost:8080/health and accept swagger docs by http://localhost:8080/swagger/index.html.

gin-template's People

Contributors

arashi87 avatar

Stargazers

C.W. Chien avatar

Watchers

 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.