Code-Memo

Project layout and CLI structure

There isn’t a single “official” Go project layout, but there are strong conventions that help DevOps tooling stay maintainable.

Minimal layout (small tool)

mytool/
  go.mod
  main.go
  internal/
    ...

Common layout (service or multi-command CLI)

myrepo/
  go.mod
  cmd/
    mytool/        # main package for CLI/service
      main.go
    mytool-agent/  # optional second binary
      main.go
  internal/        # private packages used by cmd/*
    config/
    run/
    version/
  pkg/             # optional: public packages intended for reuse
  scripts/
  Makefile

cmd/ convention

internal/ convention

CLI frameworks

Version information

Expose a --version flag and inject version at build time (see builds/release pages).