Fiber backend template for Create Go App CLI
Go-laravel is an Laravel Framework inspired backend template 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.
- Create a new project with Fiber:
git clone git@gitlab.com:d6825/golang_template.git-
Rename
.env.exampleto.envand fill it with your environment values. -
Install Docker and the following useful Go tools to your system:
- golang-migrate/migrate for apply migrations
- github.com/swaggo/swag for auto-generating Swagger API docs
- github.com/securego/gosec for checking Go security issues
- github.com/go-critic/go-critic for checking Go the best practice issues
- github.com/golangci/golangci-lint for checking Go linter issues
- gorm.io/gorm for checking GORM issues
- github.com/robfig/cron/v3 for checking Go cron issues
| Name | Version | Type |
|---|---|---|
| gofiber/fiber | v2.34.0 |
core |
| gofiber/jwt | v2.2.7 |
middleware |
| arsmn/fiber-swagger | v2.31.1 |
middleware |
| stretchr/testify | v1.7.1 |
tests |
| golang-jwt/jwt | v4.4.1 |
auth |
| joho/godotenv | v1.4.0 |
config |
| jmoiron/sqlx | v1.3.5 |
database |
| jackc/pgx | v4.16.1 |
database |
| go-sql-driver/mysql | v1.6.0 |
database |
| go-redis/redis | v8.11.5 |
cache |
| swaggo/swag | v1.8.2 |
utils |
| google/uuid | v1.3.0 |
utils |
| go-playground/validator | v10.10.0 |
utils |
Folder with business logic only. This directory doesn't care about what database driver you're using or which caching solution your choose or any third-party things.
./app/controllersfolder for functional controllers (used in routes)./app/modelsfolder for describe business models and methods of your project./app/queriesfolder for describe queries for models of your project./app/helpersfolder for describe helpers of your project./app/interfacesfolder for describe interfaces for repository, service, and controller of your project./app/providersfolder for describe providers and binding interface of your project./app/servicesfolder for describe services for controller of your project./app/repositoriesfolder for describe repository for service of your project./app/testsfolder for describe unit testing for your project
Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.
Folder with project-specific functionality. This directory contains all the project-specific code tailored only for your business use case, like configs, middleware, routes or utils.
./pkg/configsfolder for configuration functions./pkg/middlewarefolder for add middleware (Fiber built-in and yours)./pkg/constfolder for describeconstof your project./pkg/routesfolder for describe routes of your project./pkg/utilsfolder with utility functions (server starter, error checker, etc)
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 or cache server instance and storing migrations.
./platform/cachefolder with in-memory cache setup functions (by default, Redis)./platform/databasefolder with database setup functions (by default, PostgreSQL)./platform/migrationsfolder with migration files (used with golang-migrate/migrate tool)
# .env
# Stage status to start server:
# - "dev", for start server without graceful shutdown
# - "prod", for start server with graceful shutdown
STAGE_STATUS="dev"
# Server settings:
SERVER_HOST="127.0.0.1"
SERVER_PORT=3000
SERVER_READ_TIMEOUT=60
# JWT settings:
JWT_SECRET_KEY="\secret"
JWT_SECRET_KEY_EXPIRE_MINUTES_COUNT=15
JWT_REFRESH_KEY="refresh"
JWT_REFRESH_KEY_EXPIRE_HOURS_COUNT=720
# Database settings:
DB_TYPE="mysql" # pgx or mysql
DB_HOST="127.0.0.0"
DB_PORT=3306
DB_USER="root"
DB_PASSWORD=""
DB_NAME="digitels_api"
DB_SSL_MODE="disable"
DB_MAX_CONNECTIONS=100
DB_MAX_IDLE_CONNECTIONS=10
DB_MAX_LIFETIME_CONNECTIONS=2
# Gorm settings:
GORM_MYSQL="root:@tcp(127.0.0.1:3306)/midtrans?charset=utf8mb4&parseTime=True&loc=Local"
# Redis settings:
REDIS_HOST="cgapp-redis"
REDIS_PORT=6379
REDIS_PASSWORD=""
REDIS_DB_NUMBER=0
# Goose settings:
GOOSE_DRIVER="mysql"
## ⚠️ License