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.
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 forPostgreSQL
,MySQL
orMariaDB
, andSqlite3
- 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
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
To run the server:
make run
To build the project
make build
Back to Table of Content or back to Top
From the list of requirements, I still have to:
- Add test
- Add docs
- Add swagger
- Add simple blogging app