Skip to content

serod11/gofiber-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go REST API Boilerplate

This repository is a lightweight and structured Go (Golang) boilerplate codebase. It follows best practices to ensure a clean and maintainable codebase.

The codebase provides the following features:

  • Clean code
  • Dependency injection
  • Unit test
  • Environment dependent application configuration management
  • Database migration
  • Live reloading during development

The codebase uses the following Go packages.

Project Layout

.
├── cmd                  main applications of the project
│   └── server           the API server application
├── pkg                  reusable packages
│   ├── config           config
│   ├── handler          routes and handlers
│   ├── model            database entities
│   ├── service          bussiness logic
│   └── utils            utility functions like initialize database connection 
└── test                 test files   

The top level directories cmd, pkg are commonly found in other popular Go projects, also you can create internal directory to separate reusable packages into public and private packages. Standard Go Project Layout.

Getting Started

To run this project you have to have running postgres database and Go 1.18 or above installed locally. Then create pkg/config/envs/.env and set environment variables.

# download repository
git clone https://github.com/serod11/gofiber-boilerplate.git

cd gofiber-boilerplate

# run the REST API server
make run

# or run the API server with live reloading, which is useful during development
# requires air to be installed locally (https://github.com/cosmtrek/air)
make run-live

# run unit test
make unit-test

# build binary executable
make build

At this time, you have a REST API server running at http://127.0.0.1:8080. It provides following endpoints:

  • GET /health: a healthcheck service
  • GET /book: returns all books from database book table
  • GET /book/:id: returns a book by id
  • POST /book: add new book

Try the URL http://localhost:8080/healthcheck, and you should see {"status": "OK"} displayed.

curl -X GET http://localhost:8080/health

Authors