Skip to content

reitzig/template-goapp

Repository files navigation

license release GitHub release date Tests Go Report Card GoApp Template

Template: Go application

Just how I set up my go apps, which I most certainly do not claim to be best practice or anything. Comments welcome!

Features

  • spf13/cobra for implementing the command-line interface
  • Acceptance tests with Cucumber

To Do

Things I want to include, but haven't gotten around to yet:

  • Go: set up logging
  • Go: reading config files with spf13/viper
  • CI: run tests before releasing
  • CI: test/Dockerfile should use versions from mise config

Developer Setup

Testing

  • We include a test workflow that runs unit and acceptance tests with coverage.
  • Run unit tests through go test, as per usual.
  • Run acceptance tests through test/Dockerfile; a run configuration for IDEA/GoLand is included.
  • Run acceptance tests with coverage like so:
    docker rm template-goapp-test
    rm -f test/coverage/*
    
    docker build -f test/Dockerfile -t template-goapp-test . \
      && docker run -it --name template-goapp-test template-goapp-test \
      && docker cp template-goapp-test:/home/test/app/coverage test/
    go tool covdata percent -i=test/coverage

Tooling

Limitations

  • Trigger Release creates a release draft without a tag; publishing the draft will create the tag on main -- don't wait around!

Instantiating the template

  • Install aqua and mise
  • "Use this template" from GitHub web UI
  • Change some settings on GitHub:
    • Add label no changelog
    • Activate RenovateBot for the new repository (Docs)
  • Clone your new repository
  • Run aqua install (or install the tools listed above in whichever way pleases you)
  • Run mise install (or install matching Go and Ruby in whichever you pleases you)
  • Run lefthook install (optional)
  • rm .changes/unreleased/* .changes/v*.md && changie merge
  • Replace all occurrences of [reitzig/]template-goapp with [your-account/]your-app
  • Rewrite README, replace LICENSE
    • If you want to keep the badge linking to this template <3, you may also want to replace the linked revision to the one you used.