Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.go text eol=lf
go.mod text eol=lf
go.sum text eol=lf
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://json.schemastore.org/dependabot-2.0.json
version: 2
updates:
- package-ecosystem: "github-actions"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: CI

on:
Expand Down Expand Up @@ -50,6 +51,9 @@ jobs:
echo ''
make env

- name: Check shell files
run: make ci-sh

- name: ci-gen-n-format
run: make ci-gen-n-format

Expand Down
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json

# https://golangci-lint.run/usage/configuration/
# https://golangci-lint.run/usage/linters/

Expand All @@ -21,6 +23,7 @@ output:
linters:
enable-all: true
disable:
- exportloopref # deprecated
- exhaustruct # TODO: reconsider
- depguard # TODO: reconsider
- funlen # TODO: reconsider
Expand All @@ -30,6 +33,10 @@ linters:
- varnamelen
- nonamedreturns
- testpackage
- godox
- godot
- gochecknoglobals
- mnd

issues:
# https://golangci-lint.run/usage/false-positives/#default-exclusions
Expand All @@ -50,7 +57,6 @@ linters-settings:
unused:
field-writes-are-uses: false
post-statements-are-reads: false
exported-is-used: true
exported-fields-are-used: true
parameters-are-used: true
local-variables-are-used: false
Expand Down
9 changes: 7 additions & 2 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"goimports",
"gojq",
"golangci",
"gomod",
"GOPATH",
"GOVERSION",
"honnef",
Expand All @@ -26,17 +27,21 @@
"mvdan",
"NOTINTERMEDIATE",
"NOTPARALLEL",
"POSIX",
"proto",
"protobuf",
"PROTOBUFGO",
"PROTOC",
"SECONDEXPANSION",
"shellcheck",
"shfmt",
"staticcheck",
"trimpath"
"trimpath",
"vektra"
],
"ignorePaths": [
"vendor",
".git",
"/go.mod"
]
],
}
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
],
},
{
"name": "Run Main",
"name": "Debug Main",
"preLaunchTask": "build debug",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "${workspaceFolder}/output/goboilerplate",
"mode": "debug",
"program": "${workspaceFolder}/cmd/goboilerplate",
"debugAdapter": "dlv-dap",
"buildFlags": "",
"env": {
Expand All @@ -36,7 +36,7 @@
"APP_HTTP_OUTBOUND_TRAFFIC_LOG_LEVEL": "2",
"APP_HTTP_READ_HEADER_TIMEOUT": "3s",
"APP_SHUTDOWN_TIMEOUT": "6s",
"APP_LOG_LEVEL": "-1"
"APP_LOG_LEVEL": "DEBUG"
}
}
]
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"json.schemas": [{
"fileMatch": [
"/.vscode/cspell.json"
],
"url": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-types/cspell.schema.json"
}],
"search.exclude": {
"**/vendor": true
},
Expand Down
166 changes: 30 additions & 136 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,176 +1,70 @@
SHELL := /bin/bash
SHELL := /usr/bin/env bash

## https://www.gnu.org/software/make/manual/html_node/Parallel-Disable.html
.NOTPARALLEL:
.SECONDEXPANSION:
## NOTINTERMEDIATE requires make >=4.4
.NOTINTERMEDIATE:

GO_EXEC ?= go
export GO_EXEC
DOCKER_EXEC ?= docker
export DOCKER_EXEC

MODULE := $(shell cat go.mod | grep -e "^module" | sed "s/^module //")
VERSION ?= 0.0.0
X_FLAGS = \
-X '$(MODULE)/build.Version=$(VERSION)' \
-X '$(MODULE)/build.Branch=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || true)' \
-X '$(MODULE)/build.Commit=$(shell git rev-parse HEAD 2>/dev/null || true)' \
-X '$(MODULE)/build.CommitShort=$(shell git rev-parse --short HEAD 2>/dev/null || true)' \
-X '$(MODULE)/build.Tag=$(shell git describe --tags 2>/dev/null || true)'
IMAGE_NAME ?= goboilerplate
IMAGE_TAG ?= latest

GO_PACKAGES = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor ./...
GO_FOLDERS = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor -f '{{ .Dir }}' ./...
GO_FILES = find . -type f -name '*.go' -not -path './vendor/*'

export GO111MODULE := on
#export GOFLAGS := -mod=vendor
GOPATH := $(shell go env GOPATH)
GO_VER := $(shell go env GOVERSION)
BUILD_OUTPUT ?= $(CURDIR)/output

include $(CURDIR)/scripts/go.mk
include $(CURDIR)/scripts/docker.mk
include $(CURDIR)/scripts/tools.mk

.DEFAULT_GOAL=default
.PHONY: default
default: checks build

.PHONY: mod
mod:
$(GO_EXEC) mod tidy -go=1.23
$(GO_EXEC) mod verify

.PHONY: vendor
vendor:
$(GO_EXEC) mod vendor

# https://go.dev/ref/mod#go-get
# -u flag tells go get to upgrade modules
# -t flag tells go get to consider modules needed to build tests of packages named on the command line.
# When -t and -u are used together, go get will update test dependencies as well.
.PHONY: go-deps-upgrade
go-deps-upgrade:
$(GO_EXEC) get -u -t ./...
$(GO_EXEC) mod tidy -go=1.23
$(GO_EXEC) mod vendor

# https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies
# https://pkg.go.dev/cmd/compile
# https://pkg.go.dev/cmd/link

#BUILD_FLAGS := -mod=vendor -a -ldflags "-s -w $(X_FLAGS) -extldflags='-static'" -tags '$(TAGS)'
BUILD_FLAGS := -mod=vendor -a -ldflags '-s -w $(X_FLAGS)' -tags '$(TAGS)'
BUILD_FLAGS_DEBUG := -mod=vendor -ldflags '$(X_FLAGS)' -tags '$(TAGS)'

.PHONY: build
build: $(shell ls -d cmd/* | sed -e 's/\//./')

cmd.%: CMDNAME=$*
cmd.%:
$(GO_EXEC) env
@echo ''
CGO_ENABLED=0 $(GO_EXEC) build $(BUILD_FLAGS) -o $(BUILD_OUTPUT)/$(CMDNAME) ./cmd/$(CMDNAME)

dbg.%: BUILD_FLAGS=$(BUILD_FLAGS_DEBUG)
dbg.%: cmd.%
@echo "debug binary done"

.PHONY: clean
clean:
rm -rf $(BUILD_OUTPUT)

# man git-clean
.PHONY: git-reset
git-reset:
git reset --hard
git clean -fd

## https://docs.docker.com/reference/cli/docker/buildx/build/
## --output='type=docker'
## --output='type=image,push=true'
## --platform=linux/arm64
## --platform=linux/amd64,linux/arm64,linux/arm/v7
## --platform=local
## --progress='plain'
## make DOCKER_BUILD_PLATFORM=linux/arm64 image
DOCKER_BUILD_PLATFORM ?= local
DOCKER_BUILD_OUTPUT ?= type=docker
.PHONY: image
image:
$(DOCKER_EXEC) buildx build \
--output='type=docker' \
--file='$(CURDIR)/build/docker/Dockerfile' \
--tag='$(IMAGE_NAME):$(IMAGE_TAG)' \
--platform='$(DOCKER_BUILD_PLATFORM)' \
--output='$(DOCKER_BUILD_OUTPUT)' \
.

DOCKER_COMPOSE_EXEC ?= $(DOCKER_EXEC) compose -f $(CURDIR)/deployments/local/docker-compose.yml

.PHONY: compose-up
compose-up:
$(DOCKER_COMPOSE_EXEC) up --force-recreate --build

.PHONY: compose-up-detach
compose-up-detach:
$(DOCKER_COMPOSE_EXEC) up --force-recreate --build --detach

.PHONY: compose-down
compose-down:
$(DOCKER_COMPOSE_EXEC) down --volumes --rmi local --remove-orphans

# If the first target is "compose-exec"
# remove the first argument 'compose-exec' and store the rest in DOCKER_COMPOSE_ARGS
# and ignore the subsequent arguments as make targets.
# (using spaces for indentation)
ifeq (compose-exec,$(firstword $(MAKECMDGOALS)))
DOCKER_COMPOSE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(DOCKER_COMPOSE_ARGS):;@:)
endif

.PHONY: compose-exec
compose-exec:
$(DOCKER_COMPOSE_EXEC) exec $(DOCKER_COMPOSE_ARGS)

.PHONY: env
env:
@echo "Module: $(MODULE)"
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Module \e[0m \e[0;90m<<<\e[0m"
@echo "$(MODULE)"
@echo ""

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Go env \e[0m \e[0;90m<<<\e[0m"
$(GO_EXEC) env
@echo ""
@echo ">>> Packages:"

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Packages \e[0m \e[0;90m<<<\e[0m"
$(GO_PACKAGES)
@echo ""
@echo ">>> Folders:"

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Folders \e[0m \e[0;90m<<<\e[0m"
$(GO_FOLDERS)
@echo ""
@echo ">>> Files:"

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Files \e[0m \e[0;90m<<<\e[0m"
$(GO_FILES)
@echo ""
@echo ">>> Tools:"

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Tools \e[0m \e[0;90m<<<\e[0m"
@echo '$(TOOLS_BIN)'
@echo ""
@echo ">>> Path:"

@echo -e "\e[0;90m>>>\e[0m \e[0;94m Path \e[0m \e[0;90m<<<\e[0m"
@echo "$${PATH}" | tr ':' '\n'
@echo ""

.PHONY: test
test:
CGO_ENABLED=1 $(GO_EXEC) test -timeout 60s -race -tags="$(TAGS)" -coverprofile cover.out -covermode atomic ./...
@$(GO_EXEC) tool cover -func cover.out
@rm cover.out
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Shell \e[0m \e[0;90m<<<\e[0m"
@echo "SHELL=$${SHELL}"
@echo "BASH=$${BASH}"
@echo "BASH_VERSION=$${BASH_VERSION}"
@echo "BASH_VERSINFO=$${BASH_VERSINFO}"
@echo ""

.PHONY: checks
checks: vet staticcheck gofumpt goimports golangci-lint-github-actions

.PHONY: run
run:
$(GO_EXEC) run -mod=vendor ./cmd/goboilerplate

.PHONY: ci-gen-n-format
ci-gen-n-format: goimports gofumpt
./scripts/git-check-dirty

.PHONY: ci-mod
ci-mod: mod
./scripts/git-check-dirty

.PHONY: ci-sh
ci-sh: shfmt shellcheck
@./scripts/git-check-dirty
Loading
Loading