Use cli tool to troubleshoot external API service quickly.

golang CLI Template

CircleCI Build status GitHub Actions codecov GoDoc

golang project template for building CLI

Setup

Setup by Command

  1. git clone https://github.com/mpppk/cli-template your_awesome_tool
  2. Replace all strings cli-template in this repository to your_awesome_tool

Setup on GitHub

Click "Use this template" button on GitHub project page.

Project structure

Application layers

  • /cmd includes golang files which implements command and sub commands.
  • /domain includes golang files which implements domain model. This package should not depend on other layers.
  • /handler includes golang files which implements handlers of http request.
  • /usecase includes golang files which implements application use cases. This package is only allowed to depend on domain layer.

Others

  • /util includes golang files which implements utilities. All layers can depend on this package. This package should not depend on other packages.
  • /scripts includes scripts
  • /testdata includes data files for tests. (see https://golang.org/cmd/go/#hdr-Test_packages)

For more detail, see golang-standards/project-layout.

Add new sub command

If you want to create new sub command, Add new go file to /cmd.

For more details, see spf13/cobra.

Task runner

Use Makefile.

Error handling

Use golang.org/x/xerrors.

Documentation

Write godoc(example code) or Example test(example code).

Testing

Don't write test in same package, instead put to package-name_test package.
For example, test of domain/sum.go is in domain_test package, not domain package.
To use unexported variables or functions in test, expose these by export_test.go file.
(ex. /internal/option/root_export_test.go)

For more details, see this article(Japanese).

cmd test

Recommended way is to wrap cobra.Command instance by func (unlike the code generated by cobra add). For example, see cmd/sum_test.go.

with file system

This template depends spf13/afero.
afero.OsFs is used in packages and afero.MemMapFs is used in tests. For example, see cmd/sum_test.go#TestSumWithOutFile

Auto release via Circle CI powered by goreleaser

Create version tag (e.g. v0.0.1) and push to GitHub.
Then goreleaser will release the new version on Circle CI.
(Before push tag, you must provide GitHub token to Circle CI as environment variable)

For more details, see my article (Japanese).

Build & Run Docker image

$ docker build -t cli-template .
...
$ docker run cli-template sum 1 2
3

SaaS integration

Circle CI

This template includes .circleci/config.yml.

AppVeyor

This template includes appveyor.yml.

CodeCov

Makefile includes codecov task which send coverage to CodeCov.
Circle CI also send coverage to CodeCov by its job.

Renovate

This template includes renovate.json.

README template


cli-template

Installation

MacOS

Linux

Download from GitHub Releases

Windows

Download from GitHub Releases

Usage

Write usage of your awesome tool here

Similar Resources

Quickly connect to your Kubernetes Cluster with Tailscale

tsk tsk is a quick and magical way to connect your Kubernetes cluster to your Tailscale Tailnet. Installation tsk requires you have Pulumi installed.

Dec 17, 2022

OC Wrapper to facilitate switch clusters quickly

Description OCS is a wrapper for openshift cli-client oc logins to facilitate switching between multiple clusters easily. Install CP binary from repo/

Jan 10, 2022

A simple webdev utility program that allows developers to quickly validate and format JSON code

Toolbox CLI A simple webdev utility program that allows developers to quickly validate and format JSON code, convert from UNIX epoch to timestamp and

Jan 4, 2022

Automated-gke-cilium-networkpolicy-demo - Quickly provision and tear down a GKE cluster with Cilium enabled for working with Network Policy.

Automated GKE Network Policy Demo Before running the automation, make sure you have the correct variables in env-automation/group_vars/all.yaml. There

Jan 1, 2022

Quickly cross-compile your C code

Quickly cross-compile your C code

WORK IN PROGRESS: Viceroy is a very early work in progress and is subject to breaking changes. It's also subject to not really working all that well y

Aug 19, 2022

Open Service Mesh (OSM) is a lightweight, extensible, cloud native service mesh that allows users to uniformly manage, secure, and get out-of-the-box observability features for highly dynamic microservice environments.

Open Service Mesh (OSM) is a lightweight, extensible, cloud native service mesh that allows users to uniformly manage, secure, and get out-of-the-box observability features for highly dynamic microservice environments.

Open Service Mesh (OSM) Open Service Mesh (OSM) is a lightweight, extensible, Cloud Native service mesh that allows users to uniformly manage, secure,

Jan 2, 2023

Cheiron is a Kubernetes Operator made with OperatorSDK for reconciling service account and attaching imagePullSecrets to service accounts automatically

anny-co/cheiron NOTE: Cheiron is currently in very early stages of development and and far from anything usable. Feel free to contribute if you want t

Sep 13, 2021

Nycmesh-tool - nycmesh-tool CLI

nycmesh-tool nycmesh-tool CLI Features At the moment, the tool is pretty sparse. It provides the top level nycmesh-tool command, with subcommands for:

Jun 17, 2022

This plugin helps you to use the AWS Command Line Interface (AWS CLI) to start and end sessions to your managed instances

Session Manager Plugin This plugin helps you to use the AWS Command Line Interface (AWS CLI) to start and end sessions to your managed instances. Sess

Dec 28, 2022
crud is a cobra based CLI utility which helps in scaffolding a simple go based micro-service along with build scripts, api documentation, micro-service documentation and k8s deployment manifests

crud crud is a CLI utility which helps in scaffolding a simple go based micro-service along with build scripts, api documentation, micro-service docum

Nov 29, 2021
kubetnl tunnels TCP connections from within a Kubernetes cluster to a cluster-external endpoint, e.g. to your local machine. (the perfect complement to kubectl port-forward)

kubetnl kubetnl (kube tunnel) is a command line utility to tunnel TCP connections from within a Kubernetes to a cluster-external endpoint, e.g. to you

Dec 16, 2022
A simple multi-layered config loader for Go. Made for smaller projects. No external dependencies.

gocfg ⚠️ Work in progress! A simple multi-layered config loader for Go. Made for smaller projects. No external dependencies. Example From main.go: //

Dec 26, 2021
Using this you can access node external ip address value from your pod.

Using this you can access node external ip address value from your pod.

Jan 30, 2022
Injective-price-oracle-ext - Injective's Oracle with dynamic price feeds (for External Integrations)

injective-price-oracle Injective's Oracle with dynamic price feeds. Allows anyon

Aug 29, 2022
Injective's Oracle with dynamic price feeds (for External Integrations)

Injective's Oracle with dynamic price feeds. Allows anyone to start their own pre-approved price submission process to the oracle module on the Injective Chain.

Aug 29, 2022
Igo Agent is the agent of Igo, a command-line tool, through which you can quickly start Igo

igo agent 英文 | 中文 Igo Agent is the agent of Igo, a command-line tool, through which you can quickly start Igo, and other capabilities may be added lat

Dec 22, 2021
cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API.

Overview cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resou

Oct 27, 2022
ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run, exec, cp, logs, stop)
ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run, exec, cp, logs, stop)

English / 日本語 ecsk ECS + Task = ecsk ?? ecsk is a CLI tool to interactively use frequently used functions of docker command in Amazon ECS. (docker run

Dec 13, 2022
A template repository to quickly scaffold a Kubewarden policy written with Go language

go-policy-template This is a template repository that can be used to to quickly scaffold a Kubewarden policy written with Go language. Don't forget to

Sep 7, 2022