In the Golang framework itself, to create a REST API project, there is currently no feature to generate project structure templates. Not like other programming languages such as the Springboot Framework (Java), ExpressJS (NodeJS), Laravel (PHP), and so on.
So for the initial setup of the project, you have to make it yourself. Here, I will create a project template or skeleton that uses various Golang frameworks (Gin, Chi, Echo, etc.). The tools installed in this project are Gorm, PostgreSQL, Redis, and Basic Auth. And accompanied by a simple CRUD REST API, unit tests, and Dockerize.
Structure Response API
Error
{
"status": "status error",
"code": 10, // code internal error
"message": {
"id": "message error language Indonesian",
"en": "message error language English"
}
}
Success response message
{
"status": "Created", // status success
"message": "data created" // message detail success
}
Success response Multiple message
{
"status": "Created", // status success
"message": {
"id": "Data berhasil dibuat", // message language id detail success
"en": "Data created successfully" // message language english detail success
}
}
Success Single Data
{
"status": "Created", // status success
"data": {} // response data
}
Success Multiple Data
{
"status": "Success", // status success
"meta": {
"page": 1, // current page
"limit": 10, // current limit per page
"total_records": 3 // total records
},
"data": [] // response data
}
Skeleton Project Using Framework Gin
Repository details if found can be checked here
git clone https://github.com/adamnasrudin03/go-skeleton-gin.git
Skeleton Project Using Framework Chi
Repository details if found can be checked here
git clone https://github.com/adamnasrudin03/go-skeleton-chi.git
Skeleton Project Using Framework Echo
Repository details if found can be checked here
git clone https://github.com/adamnasrudin03/go-skeleton-echo.git
Skeleton Project Using Framework Gorilla Mux
Repository details if found can be checked here
git clone https://github.com/adamnasrudin03/go-skeleton-mux.git
Skeleton Project Using Framework Fiber
Repository details if found can be checked here
git clone https://github.com/adamnasrudin03/go-skeleton-fiber.git
Reference
- Gorm Documentation
- Go Validator documentation
- Gin Documentation
- Chi Documentation
- Echo Documentation
- Gorilla Mux Documentation
- Fiber Documentation
Enjoy and happy coding!