GithubHelp home page GithubHelp logo

kevinzie / fiber-go-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hrshadhin/fiber-go-boilerplate

0.0 0.0 0.0 129 KB

๐Ÿš€ Production-ready Golang based boilerplate application with Fiber web framework

License: MIT License

Go 93.21% Makefile 3.91% Dockerfile 2.88%

fiber-go-boilerplate's Introduction

Fiber Go Boilerplate

Is a production-ready golang based boilerplate application with Fiber Go web framework. For any fiber go application, just clone the repo & rename the application name.

Fiber is an Express.js inspired web framework build on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.

Tools & Libraries used

โšก๏ธ Quick start

  • Install docker, golang-migrate & swag
  • Rename .env.example to .env
  • Run project by this command:
    make docker.run
  • Visit http://localhost:5000 or http://localhost:5000/swagger/
  • Stop make docker.stop

APIs

๐Ÿ“ฆ Used packages

Name Version Type
gofiber/fiber v2.7.1 core
gofiber/jwt v2.2.1 middleware
arsmn/fiber-swagger v2.6.0 middleware
stretchr/testify v1.7.0 tests
dgrijalva/jwt-go v3.2.2 auth
joho/godotenv v1.3.0 config
jmoiron/sqlx v1.3.3 database
jackc/pgx v4.11.0 database
sirupsen/logrus v1.8.1 logging
swaggo/swag v1.7.0 utils
google/uuid v1.2.0 utils
go-playground/validator v10.5.0 utils

๐Ÿ—„ Project structure

/app

Folder with business logic only. This directory doesn't care about what database driver you're using.

  • /app/controller folder for functional controller (used in routes)
  • /app/dto Data Transfer Objects(DTO) folder for transform data before sent to API clients
  • /app/model folder for describe business models and methods of your project
  • /app/repository folder for perform database operations for models of your project

/cmd

Main applications for this project.

The directory name for each application should match the name of the executable you want to have (e.g., /cmd/server /cmd/cron). Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the /pkg directory.

/docs

Folder with API Documentation.

This directory contains config files for auto-generated API Docs by Swagger, screenshots and any other documents related to this project.

/pkg

Folder with project-specific functionality. This directory contains all the project-specific code tailored only for your business use case.

  • /pkg/config folder for configuration functions
  • /pkg/middleware folder for add middleware (Fiber built-in and yours)
  • /pkg/route folder for describe routes of your project
  • /pkg/validator folder with validation functions

/platform

Folder with platform-level logic. This directory contains all the platform-level logic that will build up the actual project, like setting up the database, logger instance and storing migrations, seeds(demo data).

  • /platform/database folder with database setup functions (by default, PostgreSQL)
  • /platform/logger folder with better logger setup functions (by default, Logrus)
  • /platform/migrations folder with migration files (used with golang-migrate/migrate tool)
  • /platform/seeds folder with demo data for application rapid setup. mostly sql scripts

โš™๏ธ Configuration

# .env
# APP settings:
APP_HOST="0.0.0.0"
APP_PORT=5000
APP_READ_TIMEOUT=30
APP_DEBUG=false

# JWT settings:
JWT_SECRET_KEY="super_secret_here"
JWT_SECRET_KEY_EXPIRE_MINUTES_COUNT=120

# Database settings:
DB_HOST=fibergb-postgres
DB_PORT=5432
DB_USER=dev
DB_PASSWORD=dev
DB_NAME=fiber_go_api
DB_SSL_MODE=disable
DB_DEBUG=true
DB_MAX_OPEN_CONNECTIONS=3
DB_MAX_IDLE_CONNECTIONS=1
DB_MAX_LIFETIME_CONNECTIONS=10

๐Ÿ”จ Docker development

  • Install docker, docker-compose & golang-migrate
  • Rename .env.example to .env
  • Start db container docker-compose up db
  • Run migrations make migrate.up
  • Now start api server with hot reloading make docker.dev
  • Visit http://localhost:5000 or http://localhost:5000/swagger/

๐Ÿ”จ Local Development

  • Install PostgreSQL golang >= 1.16 golang-migrate gosec & swag
  • Rename .env.example to .env and fill it with your environment values
  • Migrate db & seed some demo data
    make migrate.up
    make seed
  • Run project by this command:
    make run
  • Visit http://localhost:5000 or http://localhost:5000/swagger/
  • Check Makefile for more commands
    # drop migration
    make migrate.down
    
    # force migration to specific version
    migrate.force
    
    # run test
    make test
    ...

โš ๏ธ License

MIT ยฉ H.R. Shadhin

fiber-go-boilerplate's People

Contributors

hrshadhin avatar

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.