A practical Golang project layout

Golayout

Golayout is a boilerplate project that containing the usage of the best practice and popular components. The code organization follows the standard go project layout.

Why this project?

Golang is a simple programming language. The standard library has many tiny and useful wheels to help your development efficiently. But there are no frameworks such as Ruby on Rails or Java Spring Boot to help you create a runnable scaffold project fast. You must combine every tiny 'wheel' manually for your project.

I had experienced several Golang projects and saw many of them made things wrong in the early stage. When the project was going to the middle of development, it has so many troubles that can't refactor the code or design painlessly. For standing the broken window theory on the book < The Pragmatic Programmer >, we should avoid the broken window in the early stages. Having a good and well-design scaffold is very important.

For learning the coding skills, we should have an environment to practice or implement our ideas to check the code whether may or may not be done. Every programmer never wants to run the pale-running code in the production without well testing. For purpose of this, we must have an easy setup environment for testing the immature code. The environment should be the same as our production, but the frustrating configurations always bothered us to running the immature code.

Project Achieved

Suppose you want to use Golang for starting a new backend project. There are many works might that have been achieved repeatedly.

  • Building a makefile for construction works.
  • Choosing and importing an RPC framework.
  • Integrating logger.
  • Writing the service register/discovering.
  • Designing the RESTFul HTTP server/doc/testing.
  • CI/CD integration.

In this project, all these works have been finished. I don't write any special business code for this project. You can clone this repository and rename it for your own. It can help you set up a Golang project immediately.

The principles applying to this project:

  • DRY(Don't repeat yourself)
  • Being simple, and follow the k.i.s.s(keep it simple, stupid).
  • Package-oriented design and all packages have a public Init function if needed. See The problems of Golang init function
  • Separated the library and business code.
  • Applying the popular components and best practices.

Usage

Install

git clone [email protected]:leyafo/golayout.git your_project
cd your_project 
sh scripts/rename.sh your_project  #rename the project name for your own

Build

make proto #build protobuf
make build   

Build the docker images

make docker_build

Run all apps

make up

Testing

curl -i http://localhost:9527/v1/version

Description of the project organization

├── bin             //store executable files     
├── buf.yaml        //protobuf building configurations
├── buf.gen.yaml    //protobuf building configurations 
├── cmd             //the name of binaries you want to build.    
├── conf            //application configurations, it should be ignored by git.  
├── deployment      //store the Dockerfile, docker-compose or other deployment configurations  
├── Makefile        //the only one make file that can build, test, pack, run the project  
├── pkg             //the library used in the project  
├── scripts         //some install or set up scripts  
├── tools           //the tools used in this project
└── internal        //business code that cannot be importable

Contribution

If you have any advice, thoughts, and best practice, feel free to commit the pull requests. This project doesn't have any historical burden or business trad-off. You can implement your thoughts in this project without trouble.

License

MIT License

Copyright (c) 2021 李亚夫

Owner
李亚夫
Truth more precisely, an accurate understanding of reality.
李亚夫
Similar Resources

A lightweight MVC framework for Go(Golang)

utron utron is a lightweight MVC framework in Go (Golang) for building fast, scalable and robust database-driven web applications. Features Postgres,

Nov 26, 2022

Eudore is the core of a golang lightweight web framework.

Eudore eudore是一个golang轻量级web框架核心,可以轻松扩展成一个技术栈专用框架,具有完整框架设计体系。 反馈和交流请加群组:QQ群373278915。 Features 易扩展:主要设计目标、核心全部解耦,接口即为逻辑。 简单:对象语义明确,框架代码量少复杂度低,无依赖库。 易用

Nov 7, 2022

a golang web mvc framework, like asp.net mvc.

goku goku is a Web Mvc Framework for golang, mostly like ASP.NET MVC. doc & api Installation To install goku, simply run go get github.com/QLeelulu/go

Dec 7, 2022

Fast and Reliable Golang Web Framework

Fast and Reliable Golang Web Framework

Gramework The Good Framework Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware What is i

Dec 18, 2022

golang crud restful api with gorm , gin and mysql DB

crud restful api with golang , gorm , gin and mysql this api does a simple CRUD operations on a single table mysql Database . this is build on top off

Feb 26, 2022

弹弹play 资源搜索节点 API 实现,基于 Cloudflare Workers 或 Golang 的两种实现。 || API implementations for "dandanplay" resource search service.

dandanplay-resource-service API implementations for "dandanplay" resource search service. 弹弹play 资源搜索节点的 API 实现。 提供基于 Cloudflare Workers 和 Golang 的两种实

Dec 5, 2022

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance. Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance.  Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo(For English Documentation Click Here) 一个使用Go语言开发的web框架。 相关工具及插件 tiger tiger是一个专门为Tigo框架量身定做的脚手架工具,可以使用tiger新建Tigo项目或者执行其他操作。

Jan 5, 2023

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

GoFrame English | 简体中文 GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang. If you're a

Jan 2, 2023

REST Layer, Go (golang) REST API framework

REST Layer, Go (golang) REST API framework

REST Layer REST APIs made easy. REST Layer is an API framework heavily inspired by the excellent Python Eve. It helps you create a comprehensive, cust

Dec 16, 2022
Example Golang API backend rest implementation mini project Point Of Sale using Gin Framework and Gorm ORM Database.

Example Golang API backend rest implementation mini project Point Of Sale using Gin Framework and Gorm ORM Database.

Dec 23, 2022
This project demonstrates a simple RESTful API built with Go and Chi.
This project demonstrates a simple RESTful API built with Go and Chi.

Go and chi RESTful API This project demonstrates a simple RESTful API built with Go and chi. This API provides the following endpoints: GET / - Verify

Dec 14, 2022
Project template for creating an RESTful webservice in Go, with relational database backend & example content.

gofound-restful Project template for creating an RESTfull webservice in Go, with relational database backend and example content. Used packages github

Dec 15, 2022
Kratos Project Template

Kratos Project Template Install Kratos go get -u github.com/go-kratos/kratos/cmd/kratos/v2@latest Create a service # Create a template project kratos

Feb 22, 2022
A Go API project using Beego(Go Framework) with Swagger UI

Beego_API_with_swagger_UI Descriptions This is a Go API project using Beego(Go F

Dec 20, 2021
Gin is a HTTP web framework written in Go (Golang).
Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Jan 3, 2023
BANjO is a simple web framework written in Go (golang)

BANjO banjo it's a simple web framework for building simple web applications Install $ go get github.com/nsheremet/banjo Example Usage Simple Web App

Sep 27, 2022
A REST framework for quickly writing resource based services in Golang.

What is Resoursea? A high productivity web framework for quickly writing resource based services fully implementing the REST architectural style. This

Sep 27, 2022
Pleasures for Web in Golang
Pleasures for Web in Golang

Rex is a library for performant & modular web development in Go, designed to work directly with net/http. Supported Versions v1.4 v1.5 v1.6 v1.7 v1.8

Sep 27, 2022
The web framework for Golang
The web framework for Golang

uAdmin the Golang Web Framework Easy to use, blazing fast and secure. Originally open source by IntegrityNet Solutions and Services For Documentation:

Dec 24, 2022