Giter VIP home page Giter VIP logo

gofiber-boilerplate's Introduction

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

gofiber-boilerplate's People

Contributors

serod11 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

monggulteam

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.