Skip to main content

Using the Taskfile

This document explains how to use the Taskfile provided in the Go REST API Boilerplate project. The Taskfile contains various commands to streamline development, testing, and deployment processes.

Prerequisites

  • Install Go Task: brew install go-task (macOS) or see installation guide
  • Ensure you have Go 1.22.5+ installed and properly configured
  • Docker should be installed for Docker-related commands

Common Commands

Development

task dev:install  # Install Air for hot reload (first time only)
task dev # Start development server with hot reload
task build # Compile the binary with caching
task run # Build and run in production mode
task clean # Clean build artifacts

Testing

task test               # Run all unit tests
task test:coverage # Run tests with coverage (generates coverage.html)
task test:unit # Run unit tests (internal/pkg only)
task test:integration # Run integration tests
task test:performance # Run performance benchmarks
task test:security # Run security tests
task test:e2e # Run end-to-end tests
task test:contract # Run contract tests
task test:all # Run all test types

Code Quality

task fmt            # Format all Go code
task fmt:check # Check code formatting
task lint # Run golangci-lint
task vuln:check # Scan for vulnerabilities

Dependencies

task mod            # Download and tidy modules
task mod:update # Update all dependencies
task mod:verify # Verify dependency integrity
task dep # Alias for 'task mod'

Docker

task docker:build   # Build Docker image
task docker:run # Run Docker container

Documentation

task docs           # Generate API docs with Swag
task docs:serve # Start documentation server

Serverless Deployment

task sls:deploy     # Deploy using Serverless Framework
task sls:remove # Remove deployment (with confirmation)

Quick Start Examples

Start development:

task dev:install  # First time only
task dev

Production build:

task mod && task build && task run

Pre-commit checks:

task fmt && task lint && task test:all

Docker deployment:

task docker:build && task docker:run

Configuration

Customize the Taskfile.yml by modifying these variables:

VariableDefaultDescription
BINARY_NAMEapiName of compiled binary
BUILD_DIR./buildBuild output directory
MAIN_FILE./cmd/apiMain entry point
DOCKER_IMAGEmy-go-apiDocker image name
VERSION0.0.1Version number

Features

  • Build Caching: Only rebuilds when source files change
  • Preconditions: Automatically checks for required tools and provides installation instructions
  • Development Mode: Hot reload with Air, excludes non-Go directories from watch
  • Smart Dependencies: Tasks automatically run dependencies when needed

Run task to see all available commands with descriptions.