This boilerplate is intended to be used as a starting point for a go application. It is not intended to be used as a but it is can be.
- Go 1.20
- Docker
- sonar-scanner - for coverage test in local
brew install sonar-scanner
- Clone the repo
git clone https://github.com/kondohiroki/go-boilerplate.git
- Install Go dependencies
go mod download
- Copy the default configuration file
cp config/config.example.yaml config/config.yaml
- Start the database
docker compose up -d
- Migrate Database
go run main.go migrate
- Run the application
# Run normally go run main.go serve-api # Run with hot reload air serve-api
- Testing (optional)
# Run unit-test make unit-test # Run api-test make api-test # Create sonar scret touch .sonar.secret echo "your-sonar-token" > .sonar.secret # Add secret to .sonar.secret # Get from sonar web
-
For those
const
, use capitalized SNAKE_CASE for public constant. For private, constant name should led by _ (underscore).Good Example
// public const BAD_REQUEST int = 400 // private const _UNAUTHORIZED int = 401
Bad Example
const BadRequest int = 400 const unauthorized int = 401
config/config.yaml
(ignored by git)- Default configuration file
cmd/root.go
config/config.yaml
is loaded by default- You can specify the configuration file with the
--config
flag
internal/app/<your-handler>/<xxx>.go
- Define your handler functions for your endpoint
internal/logger/zap_logger.go
- You can see the log settings in the
NewZapLogger
function
- You can see the log settings in the
job/
- You can add your own jobs here
scheduler/scheduler.go
- You can schedule your jobs here
- You can configure the cron expression in
config/config.yaml
- Configuration with YAML
- Logging with Zap Logger
- CLI with Cobra
- Scheduler with Cron
- PostgreSQL
- Redis Cache
- Docker
- Fiber Router
- Add Redis Reliable Queue
- As a Web Server
- HTTP API
- gRPC API
- As a CLI Application
- As a Scheduler for Cron Jobs
- Add gRPC API
- Document the code