A modern Go template for building CLI and TUI applications with best practices and powerful tools.
- π― Cobra Command Framework - Build powerful CLI applications with ease
- βοΈ Viper Configuration - Flexible configuration management with TOML, environment variables, and flags
- π Structured Logging - Beautiful logging with Charmbracelet's log package
- π¨ Charmbracelet Tools - Modern terminal UI capabilities
- π§ Environment Support -
.envfile support for local development - π¦ Modular Structure - Clean, organized project layout
- π Automated Releases - GoReleaser integration for multi-platform builds
Download the latest release from the releases page.
git clone https://github.com/theantichris/go-template.git
cd go-template
go build -o go-templatego install github.com/theantichris/go-template@latest-
Clone and rename the template:
git clone https://github.com/theantichris/go-template.git my-app cd my-app rm -rf .git git init -
Update module name:
go mod edit -module github.com/yourusername/my-app go mod tidy
-
Customize the application:
- Edit
cmd/root.goto change the command name and description - Add new commands in the
cmd/directory - Update configuration options as needed
- Edit
# Run the application
go run main.go
# Build the application
go build
# Run with debug logging
./go-template --debug
# Use custom config file
./go-template --config /path/to/config.toml
# Display help
./go-template --helpThe application supports multiple configuration sources with the following precedence:
- Command-line flags
- Environment variables
- Configuration file
- Default values
Create a .config.toml file in your home directory or current directory:
debug = true
envVar = "some-value"Create a .env file for local development:
DEBUG=true
ENV_VAR=some-valueOr set environment variables directly:
export DEBUG=true
export ENV_VAR=some-valuego-template/
βββ cmd/
β βββ root.go # Root command and configuration
βββ main.go # Application entry point
βββ go.mod # Go module dependencies
βββ go.sum # Dependency checksums
βββ README.md # Project documentation
βββ CLAUDE.md # Claude AI assistant guide
βββ SPEC.md # Project specification template
βββ LICENSE # License file
- Go 1.23.1 or higher
- Git
# Build for current platform
go build
# Build for specific platforms
GOOS=linux GOARCH=amd64 go build -o go-template-linux
GOOS=darwin GOARCH=amd64 go build -o go-template-darwin
GOOS=windows GOARCH=amd64 go build -o go-template.exeThis project uses GoReleaser for automated releases.
# Create a new tag
git tag v0.1.0
git push origin v0.1.0
# For local testing (requires GoReleaser installed)
goreleaser release --snapshot --cleanReleases are automatically built and published when a new tag is pushed to GitHub.
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with verbose output
go test -v ./...This project uses pre-commit to ensure code quality and consistency. The hooks automatically run before each commit.
macOS (Homebrew)
# Install all tools via Homebrew
brew install pre-commit golangci-lint markdownlint-cli codespellLinux (Ubuntu/Debian)
# Install available packages via apt
sudo apt update
sudo apt install pre-commit golang-golangci-lint
# Install Node.js and markdownlint-cli
sudo apt install nodejs npm
sudo npm install -g markdownlint-cli
# Install codespell via pip
sudo apt install python3-pip
pip3 install codespellWindows
# Using winget for golangci-lint
winget install GolangCI.golangci-lint
# Using pip for Python tools (requires Python installed)
pip install pre-commit codespell
# Using npm for markdownlint-cli (requires Node.js installed)
npm install -g markdownlint-cliAlternative: Using pip and npm directly (all platforms)
# Install Go linter
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Install Python tools
pip install pre-commit codespell
# Install Node.js tools
npm install -g markdownlint-cli# Install the git hooks
pre-commit install
# Run hooks manually on all files
pre-commit run --all-files
# Run hooks on staged files only
pre-commit runThe following hooks are configured:
- Go:
go fmt,go mod tidy, unit tests, andgolangci-lint - Markdown:
markdownlintwith auto-fix - Spelling:
codespellfor checking spelling errors - General: trailing whitespace, end-of-file fixer, YAML validation, large file detection, merge conflict detection
# Install Go linter
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run Go linter
golangci-lint run
# Install Markdown linter
brew install markdownlint-cli2
# Run Markdown linter
markdownlint-cli2 "**/*.md"- Cobra - CLI framework
- Viper - Configuration management
- Charmbracelet Log - Structured logging
- Charmbracelet Fang - Enhanced command execution
- Godotenv - .env file support
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The Go team for the amazing language and tools
- The Cobra and Viper teams for excellent CLI libraries
- The Charmbracelet team for beautiful terminal tools
For issues, questions, or suggestions, please open an issue.
Built with β€οΈ using Go