atc0005 / check-mail

Various tools used to monitor mail services
MIT License
9 stars 0 forks source link

Create directory structure for multiple binaries #1

Closed atc0005 closed 4 years ago

atc0005 commented 4 years ago

Will have to look into the cmd subdirectory structure that I have seen on occasion.

atc0005 commented 4 years ago

Ideas for building multiple binaries:

atc0005 commented 4 years ago

Regarding cmd/NAME patterns, here is an example of what the official Nagios plugins are called:

refs https://nagios-plugins.org/doc/man/index.html

atc0005 commented 4 years ago

Maybe check_imap_mailbox? The check_ssl_validity plugin name already sets a precedence for length. Not sure what the usual patterns are in the Go community however.

atc0005 commented 4 years ago

Not sure what the usual patterns are in the Go community however.

Particularly the underscores.

atc0005 commented 4 years ago

A very small, very brief search seems to indicate that dashes are used in longer cmd directory names. I'll go that direction for now.

atc0005 commented 4 years ago

A very small, very brief search seems to indicate that dashes are used in longer cmd directory names. I'll go that direction for now.

This is what served as a springboard for light comparison:

It's common to have a small main function that imports and invokes the code from the /internal and /pkg directories and nothing else.

Examples:

refs https://github.com/golang-standards/project-layout/tree/master/cmd

atc0005 commented 4 years ago

These projects appear to use a layout similar to what I'm looking to do here:

atc0005 commented 4 years ago

Something to keep in mind:

How are these projects (if any have multiple binaries) handling their documentation, build requirements list, etc?

Is the main README super thin with forwarding links to docs in a single subdirectory, many subdirectories, alongside the code within cmd/NAME1/?

atc0005 commented 4 years ago

Another example here:

https://github.com/jedib0t/go-pretty

atc0005 commented 4 years ago

And yet another example:

https://github.com/cli/cli

Their Makefile:

BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)

GH_VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
LDFLAGS := -X github.com/cli/cli/command.Version=$(GH_VERSION) $(LDFLAGS)
LDFLAGS := -X github.com/cli/cli/command.BuildDate=$(shell date +%Y-%m-%d) $(LDFLAGS)
ifdef GH_OAUTH_CLIENT_SECRET
    LDFLAGS := -X github.com/cli/cli/context.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(LDFLAGS)
    LDFLAGS := -X github.com/cli/cli/context.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(LDFLAGS)
endif

bin/gh: $(BUILD_FILES)
    @go build -ldflags "$(LDFLAGS)" -o "$@" ./cmd/gh

test:
    go test ./...
.PHONY: test

site:
    git worktree add site gh-pages

site-docs: site
    git -C site pull
    git -C site rm 'manual/gh*.md' 2>/dev/null || true
    go run ./cmd/gen-docs site/manual
    for f in site/manual/gh*.md; do sed -i.bak -e '/^### SEE ALSO/,$$d' "$$f"; done
    rm -f site/manual/*.bak
    git -C site add 'manual/gh*.md'
    git -C site commit -m 'update help docs'
    git -C site push
.PHONY: site-docs
atc0005 commented 4 years ago

https://github.com/MartinHeinz/go-project-blueprint

Had it as an open tab, I recall wanting to dig further into it. Not sure if it is relevant here.

atc0005 commented 4 years ago

refs atc0005/elbow#233 (and multiple other projects)

atc0005 commented 4 years ago

From https://github.com/coreos/torus/blob/b53b701fc3af89fdf5f2999ebbc3b778e8c18ccc/Makefile#L11-L16:

WHAT := torusd torusctl torusblk

build: vendor
    for target in $(WHAT); do \
        $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -o bin/$$target -ldflags "-X $(REPOPATH).Version=$(VERSION)" ./cmd/$$target; \
    done

Essentially each section would contain a similar loop to build/process each binary.