This is a modern GitHub template repository for Go projects. Use this template to create a new Go application with a standardized structure, automated tooling, and best practices built-in.
- π Standard Layout: Adopts the Standard Go Project Layout for a clean and organized codebase
- π§ Modern Tooling: Pre-configured with golangci-lint, lefthook, and moonrepo for seamless development
- π Best Practices: Follows Effective Go guidelines with automated formatting and linting
- π Ready to Deploy: Optimized build configuration with cross-compilation support
- β‘ Fast Development: Moonrepo provides consistent task running and dependency management across the project
This template comes pre-configured with:
- πΉ Go 1.24.5: Latest stable Go version with module support
- π Moonrepo: Modern build system for consistent task running and project management
- π golangci-lint: Comprehensive linting with 40+ linters for code quality
- πͺ Lefthook: Fast Git hooks for automated quality checks
- π Standard Go Layout: Organized project structure following community standards
- π Optimized Builds: Cross-compilation ready with size optimization flags
- π GitHub Templates: CODE_OF_CONDUCT.md, SECURITY.md, and LICENSE included
- β‘ Proto Tool Manager: Automated tool management with moonrepo proto
- π§ Makefile: Convenient command shortcuts for common development tasks
- proto - A multi-language version manager that will manage all required tools
- Alternatively, you can install tools separately:
- Use this template by clicking the "Use this template" button on GitHub
- Clone your new repository:
git clone https://github.com/yourusername/your-project-name.git cd your-project-name - Install tools and dependencies:
# Install all required tools (golangci-lint, lefthook) using proto proto install # Set up the project (download dependencies and install git hooks) moon :setup
# Run the application directly (development)
moon :run
# or
go run ./cmd/app
# Build and run the production binary
moon :build
./bin/appThe project defines several tasks in the moon.yml file:
moon :setup- Set up the project dependenciesmoon :clean- Clean build artifactsmoon :format- Format the codemoon :lint- Lint the codemoon :test- Run testsmoon :build- Build the projectmoon :run- Run the application
The Makefile provides the following commands (all of which call the corresponding Moonrepo commands):
make help # Show available commands
make install # Install tools and dependencies
make clean # Clean build artifacts
make format # Format the code
make lint # Lint the code
make test # Run tests
make build # Build the project
make run # Run the application
make # Equivalent to 'make clean build'This template uses golangci-lint for comprehensive code quality checks with 40+ linters:
# Check for linting issues
moon :lint
# or
make lint
# Auto-fix linting issues and format code
moon :format
# or
make formatThis template includes Lefthook for automated Git hooks to ensure code quality:
Git hooks will automatically run on:
- Pre-commit: Format code and run golangci-lint
- Commit-msg: Validate commit message format
- Pre-push: Final lint and test checks
All commit messages must follow the Conventional Commits specification:
# β
Valid commit messages
git commit -m "feat: add user authentication"
git commit -m "fix: resolve memory leak in data processing"
git commit -m "docs: update API documentation"
git commit -m "refactor: simplify error handling logic"
# β Invalid commit messages
git commit -m "add feature" # Missing type
git commit -m "Fix bug" # Wrong case
git commit -m "feat!: breaking change" # Use BREAKING CHANGE footer insteadAvailable commit types:
feat- New featuresfix- Bug fixesdocs- Documentation changesstyle- Code style changes (formatting, etc.)refactor- Code refactoringperf- Performance improvementstest- Adding or updating testsbuild- Build system changesci- CI configuration changeschore- Other changes (maintenance, etc.)revert- Reverting previous commits
# Install hooks (automatically runs during `moon :setup`)
lefthook install
# Skip hooks for a single commit (use sparingly)
git commit -m "feat: add feature" --no-verify
# Temporarily disable hooks
lefthook uninstall
# Re-enable hooks
lefthook installgo-template/
βββ cmd/
β βββ app/
β βββ main.go # Application entry point
βββ internal/
β βββ config/
β β βββ config.go # Configuration management
β βββ foo/
β βββ foo.go # Example business logic package
βββ configs/
β βββ golangci.yml # golangci-lint configuration
βββ scripts/
β βββ install.sh # Installation scripts
βββ bin/ # Built binaries (created by build)
βββ .moon/
β βββ plugins/
β βββ golangci-lint.yml # Moon plugin configuration
βββ go.mod # Go module definition
βββ moon.yml # Moonrepo project configuration
βββ Makefile # Make commands for convenience
βββ .lefthook.yml # Git hooks configuration
βββ .prototools # Proto tool versions
βββ CODE_OF_CONDUCT.md # Code of conduct
βββ SECURITY.md # Security policy
βββ LICENSE # Apache 2.0 license
βββ README.md # This file
| File | Purpose | Key Features |
|---|---|---|
| moon.yml | Moonrepo build system | Task definitions, caching, optimized builds |
| .lefthook.yml | Git hooks | Pre-commit linting, automated quality checks |
| .prototools | Tool version manager | Consistent versions across environments |
| configs/golangci.yml | Linting configuration | 40+ linters, formatting rules, quality checks |
| go.mod | Go module definition | Module path, Go version requirements |
| Makefile | Command shortcuts | Convenient wrappers for moon tasks |
| .moon/workspace.yml | Moonrepo workspace | Global project settings |
| .moon/plugins/golangci-lint.yml | Moon plugin config | Linter integration with build system |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linter:
moon :test && moon :lint - Format your code:
moon :format - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
To customize this template for your project:
- Update go.mod with your module path (replace
github.com/tab-sama/go-template) - Modify the application in
cmd/app/main.goto fit your needs - Add your business logic in the
internal/directory - Adjust golangci-lint config in
configs/golangci.ymlas needed - Update moon.yml with your project name and description
- Update this README with your project-specific information
Please see SECURITY.md for our security policy and how to report security vulnerabilities.
This project is licensed under the Apache Licenseβsee the LICENSE file for details.
- Go for the amazing programming language
- golangci-lint for comprehensive code quality checks
- Moonrepo for consistent build tooling and task management
- Lefthook for fast and reliable Git hooks
Happy coding! π If you find this template useful, please give it a βοΈ