gin-starter

module
v0.0.0-...-4598f8e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT

README

Yet Another Golang RESTfull API

A quick story about this starter-kit

So, when I tried to write my first Golang project, especially for web api, I realy don't know how to structure my project directory, file managing the file, and so on. Frequently I search for hours on Github or Googling topics regarding the best practice on how to structuring Golang Webapp project, but the deeper I dive, the confuser I get. Technically, most of the already available Golang RESTFULL API Starter Kit that I found on the net is good, but sometimes it overkill. Some of them also great, but missing some part that I need. Therefore I made my own so it will also aligned with my coding writting style as well as minimalizing the 'confusion' I may get when depending on others starter-kit. This starter-kit may not for you as writting/ programming style is personal prefference and relative for every person, but feel free to use it.

STILL IN PROGRESS

Table of Content

  1. Quick Review
  2. Directory Structure
  3. Getting Started
1. Quick review

This YET ANOTHER golang RESTFull API is using below module:

  • Gin web framework, fast and easy
  • Gorm ORM, so you doesn't need to dive to deep on the SQL. Support for PostgreSQL, MySQL or MariaDB, and Sqlite3
  • Viper for easy configuration, support yaml, toml, json, and more...
  • Golang JWT for authentification
  • Logrus for nice and easy logging feature from sirupsen
  • Air Hot Reload module for faster development

Writting pattern:

model-> repository-> service-> handler-> router (api endpoint)

Back to Table of Content or back to Top

2. Directory structure
project-directory
|-- cmd
|-- |-- app
|-- |-- | server
|-- |-- docker
|-- config
|-- dist
|-- internal
|-- |-- account
|-- |-- |-- handler
|-- |-- |-- model
|-- |-- |-- repository
|-- |-- |-- router
|-- |-- |-- service
|-- |-- blog
|-- |-- |-- handler
|-- |-- |-- model
|-- |-- |-- repository
|-- |-- |-- router
|-- |-- |-- service
|-- |-- database
|-- |-- |-- error 
|-- |-- |-- model
|-- |-- pkg
|-- pkg
|-- |-- logger
|-- |-- middleware
|-- vendor
|-- go.mod
|-- go.sum
|-- README.md
|-- Makefile

Back to Table of Content or back to Top

3. Getting started

To run the server:

make run

To build the project

make build

Back to Table of Content or back to Top

Todo

From the list of requirements, I still have to:

  • Add test
  • Add docs
  • Add swagger
  • Add simple blogging app

LICENSE

MIT

Directories

Path Synopsis
cmd
app
Main Package is use to call function from 'Server.go' file
Main Package is use to call function from 'Server.go' file
app/server
Package server Setting up main router from various app
Package server Setting up main router from various app
internal
account
Package router for 'Account' module
Package router for 'Account' module
account/handler
Package handler for Authentication Including: * Signup * Signin * RefreshToken * CheckToken
Package handler for Authentication Including: * Signup * Signin * RefreshToken * CheckToken
account/repository
Package repository for 'User'
Package repository for 'User'
account/router
Package router for 'User'
Package router for 'User'
account/service
Package service for 'User' It will implementing interfaces available on 'user repository' and create bridge for the 'repository' package and 'handler' package
Package service for 'User' It will implementing interfaces available on 'user repository' and create bridge for the 'repository' package and 'handler' package
blog/handler
Module: blog Handler for 'blog'
Module: blog Handler for 'blog'
blog/model
Module model for 'blog' model
Module model for 'blog' model
blog/repository
Module repository for model 'blog'
Module repository for model 'blog'
blog/router
Package router for 'blog'
Package router for 'blog'
config
Main Configuration
Main Configuration
database
Package database General database for CRUD operation
Package database General database for CRUD operation
pkg/auth
Authentication routine with jwt
Authentication routine with jwt
pkg/helper
Package helper for handling response to client
Package helper for handling response to client
pkg
errors
Package errors for authentication containing custom error for our app
Package errors for authentication containing custom error for our app
logger
Logger module - It will create logfile for the server
Logger module - It will create logfile for the server
middleware
Middleware to prevent unauthorized access
Middleware to prevent unauthorized access

Jump to

Keyboard shortcuts

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