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.
Download and install Golang | Docker | Make
for Windows
For local setup testing:
-
Make sure you have installed
PostgreSQL
, create role (user) and have a local DB in your computer. Mac | Windows or similar tutorials -
Install Postman (Web with Postman Agent for
localhost
request, or full support Desktop) to test calling the API
- casbin
- casbin/gorm-adapter
- go-fiber
- go-fiber/jwt
- go-fiber/swagger
- go-gorm
- go-gorm/postgres
- govalidator
Generate ECDSA256 Private Key if not existed
- Install
OpenSSL
in your computer. RememberAdd to PATH
forWindows
user - Run the below code (detailed command can be found in
Makefile
)
make generate-ecdsa
Backend in Local machine
- Install the dependencies
go get
-
Make a copy of
env.template
and rename toenv
-
Start the server
go run .
- For API document, please visit
localhost:8000/swagger
- IMPORTANT! ON FIRST RUN: A default admin user will be created with the config in the
.env
file
-
Add comments to your API source code, See Declarative Comments Format.
-
Download
Swag
by using:
go install github.com/swaggo/swag/cmd/swag@latest
- Run the Swag in your Go project root folder which contains
main.go
file, Swag will parse comments and generate required files (docs
folder anddocs/doc.go
). All the packages have been imported tomain.go
for dependency parsing when init document.
swag init
- (Optional) Use
swag fmt
format the SWAG comment. (Please upgrade to the latest version)
swag fmt
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
Folder with configuration. This directory contains utility functions for backend configuration (Eg. get environment variables)
Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.
Folder with supported middleware. This directory contains all middleware (Fiber built-in and customization in the future)
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)