golang-cli-template

command module
Version: v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 3 Imported by: 0

README

golang-cli-template

A general purpose project template for golang CLI applications

Test golangci-lint Go Report Card Go Reference codecov

This template serves as a starting point for golang commandline applications it is based on golang projects that I consider high quality and various other useful blog posts that helped me understanding golang better.

Features

  • goreleaser with deb. and .rpm package releasing
  • golangci-lint for linting and formatting
  • Golang Github Actions Stages (Linting, Testing, Releasing)
  • Gitlab CI Configuration (Linting, Testing, Releasing)
  • tested cobra setup
  • Makefile - with various useful targets (see Makefile Targets)

Project Layout

  • assets/ => docs, images, etc
  • cmd/ => commandline configurartions (flags, subcommands)
  • pkg/ => packages that are okay to import for other projects
  • internal/ => packages that are only for project internal purposes

How to use this template

GITHUB_USER="my-github-user"
PROJECT="new-golang-project"
git clone git@github.com:FalcoSuessgott/golang-cli-template.git "$PROJECT"
cd "$PROJECT"
rm -rf .git
find . -type f -exec sed -i "s/FalcoSuessgott\/golang-cli-template/$GITHUB_USER\/$PROJECT/g" {} +
make fmt
git init
git add .
git commit -m "initial commit"
git remote add origin "git@github.com:$GITHUB_USER/$PROJECT.git"

Demo Application

$> golang-cli-template                                                  
golang-cli project template demo application

Usage:
  golang-cli-template [flags]
  golang-cli-template [command]

Available Commands:
  example     example subcommand which adds or multiplies two given integers
  help        Help about any command
  version     Displays d4sva binary version

Flags:
  -h, --help   help for golang-cli-template

Use "golang-cli-template [command] --help" for more information about a command.
$> golang-cli-template 2 5 --add                                                
7

$> golang-cli-template 2 5 --multiply
10

Makefile Targets

lint

make lint

format

make fmt

formatcheck

make fmtcheck

deps

make deps

build

make build

test

make test

cover

make cover

Contribute

If you find issues in that setup or have some nice features / improvements, I would welcome an issue or a PR :)

Ideas

  • implement a create subcommand that preconfigures this project setup and all its dependencies
  • introduce viper config examples

Documentation

The Go Gopher

There is no documentation for this package.

Source Files

Directories

Path Synopsis
pkg
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL