Skip to content
/ go-template Public template
forked from mrz1836/go-template

🚀 From Zero to Go Hero: Pre-wired Template for Modern Libraries

License

Notifications You must be signed in to change notification settings

bsv-blockchain/go-template

 
 

🚀 go-template

From Zero to Go Hero: Pre-wired Template for Modern Libraries

CI / CD Quality & Security Docs & Meta Community
Latest Release
Build Status
CodeQL
SonarCloud
Go Report Card
Code Coverage
OpenSSF Scorecard
Security policy
Go version
Go docs
AGENTS.md rules
Mage Powered
Dependabot
Contributors
Last commit
Sponsor

🗂️ Table of Contents


🧩 What's Inside

go-template is a plug-and-play scaffold that lets you skip the boilerplate and jump straight to building your Go library. Clone it, rename a few placeholders, and you instantly inherit a production-grade setup:



🚀 Quick Wins

  • Clone → Tag → Release: Go from idea to a published version in under five minutes.
  • Works Everywhere: macOS, Linux, Windows (maybe lol), ARM64 – fully reproducible builds.
  • Battery-Included Examples: ready-to-run demos, benchmarks, fuzz and race tests.
  • Flexible, Not Fragile: swap or remove any piece without breaking the whole.

Tip: Run magex help right after cloning to see every command the template unlocks.






🛠 Template Kick-Off Guide (3 Easy Steps)

(delete this section once your project is initialized)


1) Clone or "Use this template"

git clone https://github.com/bsv-blockchain/go-template.git my-lib && cd my-lib

... or click Use this template on GitHub and create a new repo.


2) Install MAGE-X build tool and run the installation script

go install github.com/mrz1836/mage-x/cmd/magex@latest

# Run the install script to customize the project for your organization
magex InstallTemplate owner=yourorg repo=yourproject

Example:

# For GitHub user "acme" creating a project called "awesome-api"
magex InstallTemplate owner=acme repo=awesome-api

What does that command do?

  1. Finds & replaces names across 70+ files

    • bsv-blockchain/go-templateyourorg/yourproject
    • go-templateyourproject
    • bsv-blockchainyourorg
  2. Cleans up template artifacts

    • Removes the default social-share image so you can add your own
    • Updates module paths in go.mod
    • Fixes all GitHub badges and links
  3. Provides helpful feedback

    • Shows exactly which files were modified
    • Gives you next steps to review and commit changes

3) Touch up metadata

Edit the highlighted files so they match your project:

  • LICENSE
    • Update the year and your name or organization
  • README.md
    • Remove the "remove-this-section" block in this file
    • Modify the "About" section to describe your library
  • .github/SECURITY.md
    • Update the security policy to match your project's needs
  • .github/FUNDING.yml
    • If you want to accept funding, add your funding links here
  • .goreleaser.yml
    • Modify settings for Slack, Discord, Twitter, or Reddit if you want to announce releases
  • CODEOWNERS
    • Adjust rules for code ownership if needed

Give it a spin!

Push your initial commit and run magex version:bump push=true bump=minor and the CI/CD pipeline will take it from there. 🚀



┌──────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                          │
│                GO-TEMPLATE – YOUR README STARTS RIGHT AFTER THIS BANNER                  │
│                                                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────┘
                                         ⬇ ⬇ ⬇


📦 Installation

go-template requires a supported release of Go.

go get -u github.com/bsv-blockchain/go-template

📚 Documentation

Good to know: go-template ships with zero runtime dependencies. The only external package we use is testify and magefile — and that's strictly for tests and dev.


Development Build Commands

Get the MAGE-X build tool for development:

go install github.com/mrz1836/mage-x/cmd/magex@latest

View all build commands

magex help
Repository Features
  • Continuous Integration on Autopilot with GitHub Actions – every push is built, tested, and reported in minutes.
  • Pull‑Request Flow That Merges Itself thanks to auto‑merge and hands‑free Dependabot auto‑merge.
  • One‑Command Builds powered by battle‑tested MAGE-X targets for linting, testing, releases, and more.
  • First‑Class Dependency Management using native Go Modules.
  • Uniform Code Style via gofumpt plus zero‑noise linting with golangci‑lint.
  • Confidence‑Boosting Tests with testify, the Go race detector, crystal‑clear HTML coverage snapshots, and automatic uploads to Codecov.
  • Hands‑Free Releases delivered by GoReleaser whenever you create a new Tag.
  • Relentless Dependency & Vulnerability Scans via Dependabot, Nancy and govulncheck.
  • Security Posture by Default with CodeQL, OpenSSF Scorecard and secret‑leak detection via gitleaks.
  • Automatic Syndication to pkg.go.dev on every release for instant godoc visibility.
  • Polished Community Experience using rich templates for Issues & PRs.
  • All the Right Meta Files (LICENSE, CONTRIBUTING.md, CODE_OF_CONDUCT.md, SUPPORT.md, SECURITY.md) pre‑filled and ready.
  • Code Ownership clarified through a CODEOWNERS file, keeping reviews fast and focused.
  • Zero‑Noise Dev Environments with tuned editor settings (.editorconfig) plus curated ignore files for VS Code, Docker, and Git.
  • Label Sync Magic: your repo labels stay in lock‑step with .github/labels.yml.
  • Friendly First PR Workflow – newcomers get a warm welcome thanks to a dedicated workflow.
  • Standards‑Compliant Docs adhering to the standard‑readme spec.
  • Instant Cloud Workspaces via Gitpod – spin up a fully configured dev environment with automatic linting and tests.
  • Out‑of‑the‑Box VS Code Happiness with a preconfigured Go workspace and .vscode folder with all the right settings.
  • Optional Release Broadcasts to your community via Slack, Discord, or Twitter – plug in your webhook.
  • AI Compliance Playbook – machine‑readable guidelines (AGENTS.md, CLAUDE.md, .cursorrules, sweep.yaml) keep ChatGPT, Claude, Cursor & Sweep aligned with your repo's rules.
  • Go-Pre-commit System - High-performance Go-native pre-commit hooks with 17x faster execution—run the same formatting, linting, and tests before every commit, just like CI.
  • Zero Python Dependencies - Pure Go implementation with environment-based configuration via .env.base.
  • DevContainers for Instant Onboarding – Launch a ready-to-code environment in seconds with VS Code DevContainers and the included .devcontainer.json config.
Repository File Glossary

This glossary describes each tracked file in the repository and notes if it is required for GitHub or another external service.

File Path Description Service
.cursorrules Rules for Cursor AI integrations Cursor
.devcontainer.json VS Code dev or GitHub container configuration VS Code & GitHub
.dockerignore Paths ignored by Docker builds Docker
.editorconfig Editor configuration defaults Editor
.gitattributes Git attributes and export settings Git
.github/.env.base Shared environment variables for GitHub Actions GitHub Actions
.github/.env.custom Custom environment variables for GitHub Actions GitHub Actions
.github/AGENTS.md Contribution rules and guidelines GitHub
.github/CLAUDE.md Claude agent instructions Claude
.github/CODEOWNERS Code ownership declarations for GitHub GitHub
.github/CODE_OF_CONDUCT.md Community behavior standards GitHub
.github/CODE_STANDARDS.md Coding style guide GitHub
.github/CONTRIBUTING.md How to contribute to the project GitHub
.github/FUNDING.yml Funding links displayed by GitHub GitHub
.github/IMAGES/go-share-image.png Social sharing image GitHub
.github/ISSUE_TEMPLATE/bug_report.yml Issue template for bug reports GitHub
.github/ISSUE_TEMPLATE/feature_request.yml Issue template for feature requests GitHub
.github/ISSUE_TEMPLATE/question.yml Issue template for questions GitHub
.github/SECURITY.md Security policy GitHub
.github/SUPPORT.md Support guidelines GitHub
.github/dependabot.yml Dependabot configuration GitHub
.github/labels.yml Repository label definitions GitHub
.github/pull_request_template.md Pull request description template GitHub
.github/sweep.yaml Sweep AI configuration Sweep AI
.github/workflows/auto-merge-on-approval.yml Workflow for automatic merges GitHub Actions
.github/workflows/codeql-analysis.yml CodeQL security analysis workflow GitHub Actions
.github/workflows/dependabot-auto-merge.yml Auto merge Dependabot PRs GitHub Actions
.github/workflows/fortress.yml Fortress security & testing workflow GitHub Actions
.github/workflows/pull-request-management.yml Pull request triage workflow GitHub Actions
.github/workflows/scorecard.yml OpenSSF Scorecard workflow GitHub Actions
.github/workflows/stale.yml Close stale issues and PRs GitHub Actions
.github/workflows/sync-labels.yml Sync repository labels GitHub Actions
.gitignore Files and directories Git should ignore Git
.gitpod.yml Gitpod workspace configuration Gitpod
.golangci.json GolangCI-Lint configuration GolangCI-Lint
.goreleaser.yml GoReleaser configuration for release automation GoReleaser
.prettierignore Paths ignored by Prettier formatting Prettier
.prettierrc.yml Prettier configuration file Prettier
.vscode/extensions.json Recommended VS Code extensions VS Code
.vscode/launch.json VS Code debugging configuration VS Code
.vscode/settings.json VS Code workspace settings VS Code
.vscode/tasks.json VS Code tasks configuration VS Code
CITATION.cff Citation metadata recognized by GitHub GitHub
Dockerfile Docker image build instructions Docker
LICENSE Project license Yours!
README.md Project overview and usage Yours!
codecov.yml Codecov upload configuration Codecov
examples/example.go Example usage of the library None
go.mod Go module definition Go
go.sum Dependency checksums generated by Go Go
magefile.go Magefile with MAGE-X targets MAGE-X
template.go Main package source code Yours!
template_benchmark_test.go Go benchmark tests Go test
template_example_test.go Example tests for documentation Go test
template_fuzz_test.go Go fuzz tests Go test
template_test.go Unit tests Go test
Library Deployment

This project uses goreleaser for streamlined binary and library deployment to GitHub. To get started, install it via:

brew install goreleaser

The release process is defined in the .goreleaser.yml configuration file.

Then create and push a new Git tag using:

magex version:bump push=true bump=patch branch=master

This process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.

Pre-commit Hooks

Set up the Go-Pre-commit System to run the same formatting, linting, and tests defined in AGENTS.md before every commit:

go install github.com/mrz1836/go-pre-commit/cmd/go-pre-commit@latest
go-pre-commit install

The system is configured via .env.base and can be customized using also using .env.custom and provides 17x faster execution than traditional Python-based pre-commit hooks. See the complete documentation for details.

GitHub Workflows

🎛️ The Workflow Control Center

All GitHub Actions workflows in this repository are powered by a single configuration files – your one-stop shop for tweaking CI/CD behavior without touching a single YAML file! 🎯

Configuration Files:

  • .env.base – Default configuration that works for most Go projects
  • .env.custom – Optional project-specific overrides

This magical file controls everything from:

  • ⚙️ Go version matrix (test on multiple versions or just one)
  • 🏃 Runner selection (Ubuntu or macOS, your wallet decides)
  • 🔬 Feature toggles (coverage, fuzzing, linting, race detection, benchmarks)
  • 🛡️ Security tool versions (gitleaks, nancy, govulncheck)
  • 🤖 Auto-merge behaviors (how aggressive should the bots be?)
  • 🏷️ PR management rules (size labels, auto-assignment, welcome messages)

Workflow Name Description
auto-merge-on-approval.yml Automatically merges PRs after approval and all required checks, following strict rules.
codeql-analysis.yml Analyzes code for security vulnerabilities using GitHub CodeQL.
dependabot-auto-merge.yml Automatically merges Dependabot PRs that meet all requirements.
fortress.yml Runs the GoFortress security and testing workflow, including linting, testing, releasing, and vulnerability checks.
pull-request-management.yml Labels PRs by branch prefix, assigns a default user if none is assigned, and welcomes new contributors with a comment.
scorecard.yml Runs OpenSSF Scorecard to assess supply chain security.
stale.yml Warns about (and optionally closes) inactive issues and PRs on a schedule or manual trigger.
sync-labels.yml Keeps GitHub labels in sync with the declarative manifest at .github/labels.yml.
Updating Dependencies

To update all dependencies (Go modules, linters, and related tools), run:

magex deps:update

This command ensures all dependencies are brought up to date in a single step, including Go modules and any tools managed by MAGE-X. It is the recommended way to keep your development environment and CI in sync with the latest versions.


🧪 Examples & Tests

All unit tests and examples run via GitHub Actions and use Go version 1.24.x. View the configuration file.

Run all tests (fast):

magex test

Run all tests with race detector (slower):

magex test:race

⚡ Benchmarks

Run the Go benchmarks:

magex bench

Benchmark Results

Benchmark Iterations ns/op B/op allocs/op
Greet 21,179,739 56.59 40 2

These benchmarks reflect fast, allocation-free lookups for most retrieval functions, ensuring optimal performance in production environments. Performance benchmarks for the core functions in this library, executed on an Apple M1 Max (ARM64).


🛠️ Code Standards

Read more about this Go project's code standards.


🤖 AI Compliance

This project documents expectations for AI assistants using a few dedicated files:

  • AGENTS.md — canonical rules for coding style, workflows, and pull requests used by Codex.
  • CLAUDE.md — quick checklist for the Claude agent.
  • .cursorrules — machine-readable subset of the policies for Cursor and similar tools.
  • sweep.yaml — rules for Sweep, a tool for code review and pull request management.

Edit AGENTS.md first when adjusting these policies, and keep the other files in sync within the same pull request.


👥 Maintainers

MrZ
MrZ

🤝 Contributing

View the contributing guidelines and please follow the code of conduct.

How can I help?

All kinds of contributions are welcome 🙌! The most basic way to show your support is to star 🌟 the project, or to raise issues 💬.

Stars


📝 License

License

About

🚀 From Zero to Go Hero: Pre-wired Template for Modern Libraries

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages

  • Go 99.6%
  • Dockerfile 0.4%