Skip to content

pcminh0505/gofiber-casbin

Repository files navigation

GoFiber Admin Client with Casbin RBAC Boilerplate

This boilerplate supports a web server with Authentication (Login / Logout) and User Management. Admin role can have all accessibility to the database, while User can only change their password.

🛠 Installation Guideline

Download and install Golang | Docker | Make for Windows

For local setup testing:

  1. Make sure you have installed PostgreSQL, create role (user) and have a local DB in your computer. Mac | Windows or similar tutorials

  2. Install Postman (Web with Postman Agent for localhost request, or full support Desktop) to test calling the API

📦 Packages Dependency

⚡️ Quick Start

Generate ECDSA256 Private Key if not existed

  1. Install OpenSSL in your computer. Remember Add to PATH for Windows user
  2. Run the below code (detailed command can be found in Makefile)
make generate-ecdsa

Backend in Local machine

  1. Install the dependencies
go get
  1. Make a copy of env.template and rename to env

  2. Start the server

go run .
  1. For API document, please visit localhost:8000/swagger
  2. IMPORTANT! ON FIRST RUN: A default admin user will be created with the config in the .env file

📖 Generating Swagger API Document

  1. Add comments to your API source code, See Declarative Comments Format.

  2. Download Swag by using:

go install github.com/swaggo/swag/cmd/swag@latest
  1. Run the Swag in your Go project root folder which contains main.go file, Swag will parse comments and generate required files (docs folder and docs/doc.go). All the packages have been imported to main.go for dependency parsing when init document.
swag init
  1. (Optional) Use swag fmt format the SWAG comment. (Please upgrade to the latest version)
swag fmt

🗄 Project Structure

./api

Folder with business logic only. This directory doesn't care about what database driver you're using or any third-party things.

  • ./api/controllers folder for functional controllers (used in routes)
  • ./api/models folder for describing business models and methods
  • ./api/repositories folder for describing queries for models
  • ./api/routes folder for describing routes
  • ./api/utils folder for utility functions

./config

Folder with configuration. This directory contains utility functions for backend configuration (Eg. get environment variables)

./docs

Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.

./middleware

Folder with supported middleware. This directory contains all middleware (Fiber built-in and customization in the future)

./infra

Folder with infrastructure-level logic. This directory contains all the platform-level logic that will build up the actual project, like setting up the database

  • ./infra/database folder with database setup function (PostgreSQL)

About

Golang Web Server (Fiber) with Casbin RBAC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published