Skip to content

Commit f0fb258

Browse files
authored
drop zerolog; introduce slog (#50)
* drop zerolog; introduce slog * minors * sr * bumps * refactor make file * add script to install shellcheck * extract handlers * cleanup * make shell * all around
1 parent 2e95ad9 commit f0fb258

File tree

141 files changed

+1775
-10722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1775
-10722
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.go text eol=lf
2+
go.mod text eol=lf
3+
go.sum text eol=lf

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/dependabot-2.0.json
12
version: 2
23
updates:
34
- package-ecosystem: "github-actions"

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
12
name: CI
23

34
on:
@@ -50,6 +51,9 @@ jobs:
5051
echo ''
5152
make env
5253
54+
- name: Check shell files
55+
run: make ci-sh
56+
5357
- name: ci-gen-n-format
5458
run: make ci-gen-n-format
5559

.golangci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
13
# https://golangci-lint.run/usage/configuration/
24
# https://golangci-lint.run/usage/linters/
35

@@ -21,6 +23,7 @@ output:
2123
linters:
2224
enable-all: true
2325
disable:
26+
- exportloopref # deprecated
2427
- exhaustruct # TODO: reconsider
2528
- depguard # TODO: reconsider
2629
- funlen # TODO: reconsider
@@ -30,6 +33,10 @@ linters:
3033
- varnamelen
3134
- nonamedreturns
3235
- testpackage
36+
- godox
37+
- godot
38+
- gochecknoglobals
39+
- mnd
3340

3441
issues:
3542
# https://golangci-lint.run/usage/false-positives/#default-exclusions
@@ -50,7 +57,6 @@ linters-settings:
5057
unused:
5158
field-writes-are-uses: false
5259
post-statements-are-reads: false
53-
exported-is-used: true
5460
exported-fields-are-used: true
5561
parameters-are-used: true
5662
local-variables-are-used: false

.vscode/cspell.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"goimports",
1818
"gojq",
1919
"golangci",
20+
"gomod",
2021
"GOPATH",
2122
"GOVERSION",
2223
"honnef",
@@ -26,17 +27,21 @@
2627
"mvdan",
2728
"NOTINTERMEDIATE",
2829
"NOTPARALLEL",
30+
"POSIX",
2931
"proto",
3032
"protobuf",
3133
"PROTOBUFGO",
3234
"PROTOC",
3335
"SECONDEXPANSION",
36+
"shellcheck",
37+
"shfmt",
3438
"staticcheck",
35-
"trimpath"
39+
"trimpath",
40+
"vektra"
3641
],
3742
"ignorePaths": [
3843
"vendor",
3944
".git",
4045
"/go.mod"
41-
]
46+
],
4247
}

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
],
2323
},
2424
{
25-
"name": "Run Main",
25+
"name": "Debug Main",
2626
"preLaunchTask": "build debug",
2727
"type": "go",
2828
"request": "launch",
29-
"mode": "exec",
30-
"program": "${workspaceFolder}/output/goboilerplate",
29+
"mode": "debug",
30+
"program": "${workspaceFolder}/cmd/goboilerplate",
3131
"debugAdapter": "dlv-dap",
3232
"buildFlags": "",
3333
"env": {
@@ -36,7 +36,7 @@
3636
"APP_HTTP_OUTBOUND_TRAFFIC_LOG_LEVEL": "2",
3737
"APP_HTTP_READ_HEADER_TIMEOUT": "3s",
3838
"APP_SHUTDOWN_TIMEOUT": "6s",
39-
"APP_LOG_LEVEL": "-1"
39+
"APP_LOG_LEVEL": "DEBUG"
4040
}
4141
}
4242
]

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2+
"json.schemas": [{
3+
"fileMatch": [
4+
"/.vscode/cspell.json"
5+
],
6+
"url": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-types/cspell.schema.json"
7+
}],
28
"search.exclude": {
39
"**/vendor": true
410
},

Makefile

Lines changed: 30 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,70 @@
1-
SHELL := /bin/bash
1+
SHELL := /usr/bin/env bash
22

3+
## https://www.gnu.org/software/make/manual/html_node/Parallel-Disable.html
34
.NOTPARALLEL:
4-
.SECONDEXPANSION:
5-
## NOTINTERMEDIATE requires make >=4.4
6-
.NOTINTERMEDIATE:
7-
8-
GO_EXEC ?= go
9-
export GO_EXEC
10-
DOCKER_EXEC ?= docker
11-
export DOCKER_EXEC
12-
13-
MODULE := $(shell cat go.mod | grep -e "^module" | sed "s/^module //")
14-
VERSION ?= 0.0.0
15-
X_FLAGS = \
16-
-X '$(MODULE)/build.Version=$(VERSION)' \
17-
-X '$(MODULE)/build.Branch=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || true)' \
18-
-X '$(MODULE)/build.Commit=$(shell git rev-parse HEAD 2>/dev/null || true)' \
19-
-X '$(MODULE)/build.CommitShort=$(shell git rev-parse --short HEAD 2>/dev/null || true)' \
20-
-X '$(MODULE)/build.Tag=$(shell git describe --tags 2>/dev/null || true)'
21-
IMAGE_NAME ?= goboilerplate
22-
IMAGE_TAG ?= latest
23-
24-
GO_PACKAGES = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor ./...
25-
GO_FOLDERS = $(GO_EXEC) list -tags='$(TAGS)' -mod=vendor -f '{{ .Dir }}' ./...
26-
GO_FILES = find . -type f -name '*.go' -not -path './vendor/*'
27-
28-
export GO111MODULE := on
29-
#export GOFLAGS := -mod=vendor
30-
GOPATH := $(shell go env GOPATH)
31-
GO_VER := $(shell go env GOVERSION)
32-
BUILD_OUTPUT ?= $(CURDIR)/output
335

6+
include $(CURDIR)/scripts/go.mk
7+
include $(CURDIR)/scripts/docker.mk
348
include $(CURDIR)/scripts/tools.mk
359

3610
.DEFAULT_GOAL=default
3711
.PHONY: default
3812
default: checks build
3913

40-
.PHONY: mod
41-
mod:
42-
$(GO_EXEC) mod tidy -go=1.23
43-
$(GO_EXEC) mod verify
44-
45-
.PHONY: vendor
46-
vendor:
47-
$(GO_EXEC) mod vendor
48-
49-
# https://go.dev/ref/mod#go-get
50-
# -u flag tells go get to upgrade modules
51-
# -t flag tells go get to consider modules needed to build tests of packages named on the command line.
52-
# When -t and -u are used together, go get will update test dependencies as well.
53-
.PHONY: go-deps-upgrade
54-
go-deps-upgrade:
55-
$(GO_EXEC) get -u -t ./...
56-
$(GO_EXEC) mod tidy -go=1.23
57-
$(GO_EXEC) mod vendor
58-
59-
# https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies
60-
# https://pkg.go.dev/cmd/compile
61-
# https://pkg.go.dev/cmd/link
62-
63-
#BUILD_FLAGS := -mod=vendor -a -ldflags "-s -w $(X_FLAGS) -extldflags='-static'" -tags '$(TAGS)'
64-
BUILD_FLAGS := -mod=vendor -a -ldflags '-s -w $(X_FLAGS)' -tags '$(TAGS)'
65-
BUILD_FLAGS_DEBUG := -mod=vendor -ldflags '$(X_FLAGS)' -tags '$(TAGS)'
66-
67-
.PHONY: build
68-
build: $(shell ls -d cmd/* | sed -e 's/\//./')
69-
70-
cmd.%: CMDNAME=$*
71-
cmd.%:
72-
$(GO_EXEC) env
73-
@echo ''
74-
CGO_ENABLED=0 $(GO_EXEC) build $(BUILD_FLAGS) -o $(BUILD_OUTPUT)/$(CMDNAME) ./cmd/$(CMDNAME)
75-
76-
dbg.%: BUILD_FLAGS=$(BUILD_FLAGS_DEBUG)
77-
dbg.%: cmd.%
78-
@echo "debug binary done"
79-
80-
.PHONY: clean
81-
clean:
82-
rm -rf $(BUILD_OUTPUT)
83-
8414
# man git-clean
8515
.PHONY: git-reset
8616
git-reset:
8717
git reset --hard
8818
git clean -fd
8919

90-
## https://docs.docker.com/reference/cli/docker/buildx/build/
91-
## --output='type=docker'
92-
## --output='type=image,push=true'
93-
## --platform=linux/arm64
94-
## --platform=linux/amd64,linux/arm64,linux/arm/v7
95-
## --platform=local
96-
## --progress='plain'
97-
## make DOCKER_BUILD_PLATFORM=linux/arm64 image
98-
DOCKER_BUILD_PLATFORM ?= local
99-
DOCKER_BUILD_OUTPUT ?= type=docker
100-
.PHONY: image
101-
image:
102-
$(DOCKER_EXEC) buildx build \
103-
--output='type=docker' \
104-
--file='$(CURDIR)/build/docker/Dockerfile' \
105-
--tag='$(IMAGE_NAME):$(IMAGE_TAG)' \
106-
--platform='$(DOCKER_BUILD_PLATFORM)' \
107-
--output='$(DOCKER_BUILD_OUTPUT)' \
108-
.
109-
110-
DOCKER_COMPOSE_EXEC ?= $(DOCKER_EXEC) compose -f $(CURDIR)/deployments/local/docker-compose.yml
111-
112-
.PHONY: compose-up
113-
compose-up:
114-
$(DOCKER_COMPOSE_EXEC) up --force-recreate --build
115-
116-
.PHONY: compose-up-detach
117-
compose-up-detach:
118-
$(DOCKER_COMPOSE_EXEC) up --force-recreate --build --detach
119-
120-
.PHONY: compose-down
121-
compose-down:
122-
$(DOCKER_COMPOSE_EXEC) down --volumes --rmi local --remove-orphans
123-
124-
# If the first target is "compose-exec"
125-
# remove the first argument 'compose-exec' and store the rest in DOCKER_COMPOSE_ARGS
126-
# and ignore the subsequent arguments as make targets.
127-
# (using spaces for indentation)
128-
ifeq (compose-exec,$(firstword $(MAKECMDGOALS)))
129-
DOCKER_COMPOSE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
130-
$(eval $(DOCKER_COMPOSE_ARGS):;@:)
131-
endif
132-
133-
.PHONY: compose-exec
134-
compose-exec:
135-
$(DOCKER_COMPOSE_EXEC) exec $(DOCKER_COMPOSE_ARGS)
136-
13720
.PHONY: env
13821
env:
139-
@echo "Module: $(MODULE)"
22+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Module \e[0m \e[0;90m<<<\e[0m"
23+
@echo "$(MODULE)"
24+
@echo ""
25+
26+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Go env \e[0m \e[0;90m<<<\e[0m"
14027
$(GO_EXEC) env
14128
@echo ""
142-
@echo ">>> Packages:"
29+
30+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Packages \e[0m \e[0;90m<<<\e[0m"
14331
$(GO_PACKAGES)
14432
@echo ""
145-
@echo ">>> Folders:"
33+
34+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Folders \e[0m \e[0;90m<<<\e[0m"
14635
$(GO_FOLDERS)
14736
@echo ""
148-
@echo ">>> Files:"
37+
38+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Files \e[0m \e[0;90m<<<\e[0m"
14939
$(GO_FILES)
15040
@echo ""
151-
@echo ">>> Tools:"
41+
42+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Tools \e[0m \e[0;90m<<<\e[0m"
15243
@echo '$(TOOLS_BIN)'
15344
@echo ""
154-
@echo ">>> Path:"
45+
46+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Path \e[0m \e[0;90m<<<\e[0m"
15547
@echo "$${PATH}" | tr ':' '\n'
48+
@echo ""
15649

157-
.PHONY: test
158-
test:
159-
CGO_ENABLED=1 $(GO_EXEC) test -timeout 60s -race -tags="$(TAGS)" -coverprofile cover.out -covermode atomic ./...
160-
@$(GO_EXEC) tool cover -func cover.out
161-
@rm cover.out
50+
@echo -e "\e[0;90m>>>\e[0m \e[0;94m Shell \e[0m \e[0;90m<<<\e[0m"
51+
@echo "SHELL=$${SHELL}"
52+
@echo "BASH=$${BASH}"
53+
@echo "BASH_VERSION=$${BASH_VERSION}"
54+
@echo "BASH_VERSINFO=$${BASH_VERSINFO}"
55+
@echo ""
16256

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

166-
.PHONY: run
167-
run:
168-
$(GO_EXEC) run -mod=vendor ./cmd/goboilerplate
169-
17060
.PHONY: ci-gen-n-format
17161
ci-gen-n-format: goimports gofumpt
17262
./scripts/git-check-dirty
17363

17464
.PHONY: ci-mod
17565
ci-mod: mod
17666
./scripts/git-check-dirty
67+
68+
.PHONY: ci-sh
69+
ci-sh: shfmt shellcheck
70+
@./scripts/git-check-dirty

0 commit comments

Comments
 (0)