Git Product home page Git Product logo

gin-tpl's Introduction

Gin template

gin-tpl is backend template for gin web application

Structure

|--config/
|   |--db/db.go
|   |--route
|       |  router.go
|       |  middleware.go
|--lib/
|   |  errors.go
|--models/
|--param/
|--router/
|--service/
|--utils/
|  main.go
|  db.config.yaml
  • config init your application and load config. gin-tpl use yaml files as its config files, also you can use any other type file such as json file and gin-tpl provide function in utils/file_help.go called LoadDataFromFile to help load config from file easily. examples for load database config and route config can be found in config/db/db.go and config/route/route.go

  • lib errors definitions and some wraps for packages such as cdn, oss, sms and so on

  • models models represents the most basic abstract structures, also binding with database and cache stored in there, functions related with orm and cache are also in this directory. any io error throws by any function in models must be written to log system. packages in models can not import object from any other package except those with the same level, on the other word, any other package should be able to import models' packages without worry about cycle import problem. object in models package could contain trans method used to trans from elements in params package.

  • param holds params from outside, usually from frontend, usually combined with some objects from models package. common structures like pager which used to deal with pagination request also can be found in it.

  • router routes defined in this package. usually routes will be registered in init function. and with function WrapHandler, you can write handlers in a common way. usually binding params and trans them to object in models here.

  • service functions hold your logic in this package, usually combine your code in model, pass messages to MQ and other.

  • db.config.yaml config file.

  • main.go app entry, route register here

Usage

  • clone:

      git clone github.com/mint-leaf/gin-tpl
    
  • replace:

    • in your project root dir and replace all github.com/mint-leaf/gin-tpl in import block with YOUR_APP_NAME
  • go mod:

      go mod init {{YOUR_APP_NAME}}
    
  • if GOPROXY:

Contribute

  • PRs welcome

gin-tpl's People

Contributors

mint-leaf avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.