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.
-
Clone or open a new project with Fiber.
-
Rename
.env.example
to.env
and fill it with your environment values. -
(Opsional) 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
-
Run project by this command:
make dev
- Go to API Docs page (Swagger): 127.0.0.1:5000/swagger/index.html
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/controllers
folder for functional controllers (used in routes)./app/models
folder for describe business models and methods of your project./app/repository
folder for describe queries for models of your project./app/service
folder for describe functional and call repository for controllers of your project./app/middleware
folder for add middleware (Fiber built-in and yours)
Folder bootsrap. This directory define main app in your project.
Folder with API Documentation. This directory contains config files for auto-generated API Docs by Swagger.
Folder helper / hook. This directory helper/hook in your project.
Folder routes. This directory for define url endpoint in yout project.
./routes/routes
folder for define url endpoint in yout project./routes/injection
folder for define and call dependencies injection in yout project
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.
./config/constant
folder for configuration constant variable./config/logger
folder for initialize logger of your project./config/utils
folder 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.
./database
folder with database setup functions (by default, PostgreSQL)./database/cache
folder with in-memory cache setup functions (by default, Redis)./database/migrations
folder 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="0.0.0.0"
SERVER_PORT=5000
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="pgx" # pgx or mysql
DB_HOST="cgapp-postgres"
DB_PORT=5432
DB_USER="postgres"
DB_PASSWORD="password"
DB_NAME="postgres"
DB_SSL_MODE="disable"
DB_MAX_CONNECTIONS=100
DB_MAX_IDLE_CONNECTIONS=10
DB_MAX_LIFETIME_CONNECTIONS=2
# Redis settings:
REDIS_HOST="cgapp-redis"
REDIS_PORT=6379
REDIS_PASSWORD=""
REDIS_DB_NUMBER=0
# Cors settings
CORS_ALLOW_CREDENTIALS=true
CORS_ALLOWED_HEADERS=Accept,Authorization,Content-Type
CORS_ALLOWED_METHODS=GET,PUT,POST,PATCH,DELETE,OPTIONS
CORS_ALLOWED_ORIGINS=http://localhost:5000,http://127.0.0.1:5000
CORS_ENABLE=true
CORS_MAX_AGE_SECONDS=300
Apache 2.0 ©