A general purpose golang CLI template for Github and Gitlab

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

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 [email protected]: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 "[email protected]:$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 example 2 5 -a                                               
7

$> golang-cli-template example 2 5 -m
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
Similar Resources

Go CLI Template

go-cli-template This is template that help you to quick implement some CLI using Go. This repository is contains following. minimal CLI implementation

Dec 27, 2022

Fusozay Var Var: A CLI tool for quick text template rendering

fvv - Fusozay Var Var A CLI tool for quick text template rendering Fusozay Var Var means "have fun" It is a reference to something I see a lot Fusozay

Dec 11, 2021

A Go Template Library. A bunch of utils and collections that are not part of the Golang standard library.

gotl A Go Template Library. A bunch of utils and collections that are not part of the Golang standard library. Prerequisites This library is using ext

Dec 15, 2021

Golang Echo and html template.

golang-website-example Golang Echo and html template. move GitHub repository for hello to golang-website-example Visual Studio Code Run and Debug: lau

Feb 4, 2022

Clean arch Golang template project

Template No previous versions, still working on this one to reach v1. API Service for pssword app mobilde based on : https://github.com/bxcodec/go-cle

Sep 15, 2021

Template for Golang rest API using Fiber

Rest API Setup DB sudo -S docker-compose -f db.yml up -d Build container sudo -S docker build -t rest-api-image . Run container from image sudo -S doc

Dec 5, 2021

Clean Architecture template for Golang services

Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Jul 11, 2022

Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Nov 30, 2021

Competitive Programming Template for Golang

Go Competitive Programming Template How to use this repo? Check the commit histo

Dec 19, 2021
Comments
  • The automated release is failing 🚨

    The automated release is failing 🚨

    :rotating_light: The automated release from the master branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here are some links that can help you:

    If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


    Missing package.json file.

    A package.json file at the root of your project is required to release on npm.

    Please follow the npm guideline to create a valid package.json file.


    Good luck with your project ✨

    Your semantic-release bot :package::rocket:

  • Various review fixes

    Various review fixes

    Some things I fixed:

    • Use require.NoError(t, err) in your tests, saves you a lot boilerplate code
    • Do not use latest tags on docker images as you never know which version really is latest
    • Added deps Makefile target
    • Quoted bash variables and sub shell execution

    Some ideas:

    • Add a binary which allows to generate this repo and replaces imports. Imho something like go-template create [project-name] feels better but definitely something for the future
    • Your build target should default to the tag provided by your CI, otherwise recommend use development. You may want to add the commit hash to your version output (i.e. optionally via a flag)
    • Did you considered adding viper configurations?
  • Fix unauthenticated git protocol error

    Fix unauthenticated git protocol error

    As outlined here: https://github.blog/2021-09-01-improving-git-protocol-security-github/

    [WARNING] The 'rev' field of repo 'git://github.com/dnephin/pre-commit-golang' appears to be a mutable reference (moving tag / branch).  Mutable references are never updated after first install and are not supported.  See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details.  Hint: `pre-commit autoupdate` often fixes this.
    [INFO] Initializing environment for git://github.com/dnephin/pre-commit-golang.
    An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
    return code: 128
    expected return code: 0
    stdout: (none)
    stderr:
        fatal: remote error:
          The unauthenticated git protocol on port 9418 is no longer supported.
        Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
    
    Check the log at /home/jhewers/.cache/pre-commit/pre-commit.log
    
  • Install on macOS fails with system `sed`

    Install on macOS fails with system `sed`

    The system version of macOS sed behaves slightly different than Linux.

    install.sh fails on macOS (12 - Monterey, but probably earlier and later too) with the following error:

    sed: 1: "./cmd/version.go": invalid command code .
    

    This works fine on Linux (or on macOS with non-system sed version) :

    find . -type f -exec sed -i "s/golang-cli-template/$projectname/g" {} +
    find . -type f -exec sed -i "s/FalcoSuessgott/$user/g" {} +
    

    sed in-place replacement works slightly different on macOS: it wants an empty argument.

    find . -type f -exec sed -I "" "s/golang-cli-template/$projectname/g" {} +
    find . -type f -exec sed -I "" "s/FalcoSuessgott/$user/g" {} +
    

    Annoying, I know.

    See also https://stackoverflow.com/questions/7573368/in-place-edits-with-sed-on-os-x

    I might get around to send a PR for this, but in case I don't here's an issue at least :-)

    p.s. thank you for the project!

Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

Oct 25, 2022
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Dec 5, 2022
A template to build dynamic web apps quickly using Go, html/template and javascript
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Dec 29, 2022
Wrapper package for Go's template/html to allow for easy file-based template inheritance.

Extemplate Extemplate is a small wrapper package around html/template to allow for easy file-based template inheritance. File: templates/parent.tmpl <

Dec 6, 2022
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

quicktemplate A fast, powerful, yet easy to use template engine for Go. Inspired by the Mako templates philosophy. Features Extremely fast. Templates

Dec 26, 2022
Made from template temporalio/money-transfer-project-template-go
Made from template temporalio/money-transfer-project-template-go

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

Jan 6, 2022
Go-api-template - A rough template to give you a starting point for your API

Golang API Template This is only a rough template to give you a starting point f

Jan 14, 2022
Api-go-template - A simple Go API template that uses a controller-service based model to build its routes

api-go-template This is a simple Go API template that uses a controller-service

Feb 18, 2022
âš— The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.
âš— The most advanced CLI template on earth! Featuring automatic releases, website generation and a custom CI-System out of the box.

cli-template ✨ ⚗ A template for beautiful, modern, cross-platform compatible CLI tools written with Go! Getting Started | Wiki This template features

Dec 4, 2022
A template and a functioning example for a basic JFrog CLI plugin

hello-frog About this plugin This plugin is a template and a functioning example for a basic JFrog CLI plugin. This README shows the expected structur

Dec 8, 2021