Skip to content

Commit 65b1a2f

Browse files
committed
refactor: update interfaces to use any, improve error handling, and enhance documentation
- Refactored all interfaces and implementations to use `any` instead of `interface{}` for type consistency. - Changed `Remove` methods in service and middleware to return errors for better error propagation. - Improved documentation comments across multiple files for clarity and consistency. - Replaced `fmt.Errorf` with `ewrap.Wrap` for error wrapping in serializer and stats collector. - Fixed import order and formatting in test files. - Enhanced worker pool logic and fixed worker resizing in `pool.go`. - Improved stats collection and calculation logic in `stats` package. - Minor bug fixes and code style improvements throughout the codebase.
1 parent 5991c6f commit 65b1a2f

54 files changed

Lines changed: 1249 additions & 562 deletions

Some content is hidden

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

.golangci.yaml

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
---
2+
version: 2
3+
# Options for analysis running.
4+
run:
5+
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
6+
# If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota.
7+
# Default: the number of logical CPUs in the machine
8+
concurrency: 4
9+
# Timeout for analysis, e.g. 30s, 5m.
10+
# Default: 1m
11+
timeout: 5m
12+
# Exit code when at least one issue was found.
13+
# Default: 1
14+
issues-exit-code: 2
15+
# Include test files or not.
16+
# Default: true
17+
tests: false
18+
# List of build tags, all linters use it.
19+
# Default: []
20+
# build-tags:
21+
# - tag
22+
# If set, we pass it to "go list -mod={option}". From "go help modules":
23+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
24+
# automatic updating of go.mod described above. Instead, it fails when any changes
25+
# to go.mod are needed. This setting is most useful to check that go.mod does
26+
# not need updates, such as in a continuous integration and testing system.
27+
# If invoked with -mod=vendor, the go command assumes that the vendor
28+
# directory holds the correct copies of dependencies and ignores
29+
# the dependency descriptions in go.mod.
30+
#
31+
# Allowed values: readonly|vendor|mod
32+
# Default: ""
33+
modules-download-mode: readonly
34+
# Allow multiple parallel golangci-lint instances running.
35+
# If false, golangci-lint acquires file lock on start.
36+
# Default: false
37+
allow-parallel-runners: true
38+
# Allow multiple golangci-lint instances running, but serialize them around a lock.
39+
# If false, golangci-lint exits with an error if it fails to acquire file lock on start.
40+
# Default: false
41+
allow-serial-runners: true
42+
# Define the Go version limit.
43+
# Mainly related to generics support since go1.18.
44+
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17
45+
go: "1.25.0"
46+
47+
exclusions:
48+
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
49+
# "/" will be replaced by the current OS file path separator to properly work on Windows.
50+
# Default: []
51+
paths:
52+
- "cmd/*/test-*"
53+
54+
linters:
55+
# Enable specific linter
56+
# https://golangci-lint.run/usage/linters/#enabled-by-default
57+
default: all
58+
enable:
59+
- wsl_v5
60+
disable:
61+
- exhaustruct
62+
- depguard
63+
- ireturn
64+
- lll
65+
- tagliatelle
66+
- wsl
67+
68+
settings:
69+
cyclop:
70+
# The maximal code complexity to report.
71+
# Default: 10
72+
max-complexity: 12
73+
errcheck:
74+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
75+
# Such cases aren't reported by default.
76+
# Default: false
77+
check-type-assertions: true
78+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
79+
# Such cases aren't reported by default.
80+
# Default: false
81+
check-blank: true
82+
# To disable the errcheck built-in exclude list.
83+
# See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
84+
# Default: false
85+
disable-default-exclusions: false
86+
# List of functions to exclude from checking, where each entry is a single function to exclude.
87+
# See https://github.com/kisielk/errcheck#excluding-functions for details.
88+
exclude-functions:
89+
- fmt.Fprintf
90+
- fmt.Fprintln
91+
funlen:
92+
lines: 100
93+
lll:
94+
# Max line length, lines longer will be reported.
95+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option.
96+
# Default: 120.
97+
line-length: 150
98+
# Tab width in spaces.
99+
# Default: 1
100+
tab-width: 1
101+
102+
ireturn:
103+
# ireturn does not allow using `allow` and `reject` settings at the same time.
104+
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
105+
# keywords:
106+
# - `empty` for `any`
107+
# - `error` for errors
108+
# - `stdlib` for standard library
109+
# - `anon` for anonymous interfaces
110+
# - `generic` for generic interfaces added in go 1.18
111+
112+
# By default, it allows using errors, empty interfaces, anonymous interfaces,
113+
# and interfaces provided by the standard library.
114+
allow:
115+
- anon
116+
- error
117+
- empty
118+
- stdlib
119+
# You can specify idiomatic endings for interface
120+
- (or|er|ry)$
121+
122+
wrapcheck:
123+
# An array of strings that specify globs of packages to ignore.
124+
# Default: []
125+
ignore-package-globs:
126+
- github.com/hyp3rd/*
127+
- github.com/gofiber/fiber/*
128+
129+
varnamelen:
130+
# The longest distance, in source lines, that is being considered a "small scope".
131+
# Variables used in at most this many lines will be ignored.
132+
# Default: 5
133+
max-distance: 6
134+
# The minimum length of a variable's name that is considered "long".
135+
# Variable names that are at least this long will be ignored.
136+
# Default: 3
137+
min-name-length: 2
138+
# Check method receivers.
139+
# Default: false
140+
check-receiver: false
141+
# Check named return values.
142+
# Default: false
143+
check-return: true
144+
# Check type parameters.
145+
# Default: false
146+
check-type-param: true
147+
# Ignore "ok" variables that hold the bool return value of a type assertion.
148+
# Default: false
149+
ignore-type-assert-ok: true
150+
# Ignore "ok" variables that hold the bool return value of a map index.
151+
# Default: false
152+
ignore-map-index-ok: true
153+
# Ignore "ok" variables that hold the bool return value of a channel receive.
154+
# Default: false
155+
ignore-chan-recv-ok: true
156+
# Optional list of variable names that should be ignored completely.
157+
# Default: []
158+
ignore-names:
159+
- err
160+
# Optional list of variable declarations that should be ignored completely.
161+
# Entries must be in one of the following forms (see below for examples):
162+
# - for variables, parameters, named return values, method receivers, or type parameters:
163+
# <name> <type> (<type> can also be a pointer/slice/map/chan/...)
164+
# - for constants: const <name>
165+
#
166+
# Default: []
167+
ignore-decls:
168+
- c echo.Context
169+
- t testing.T
170+
- f *foo.Bar
171+
- e error
172+
- i int
173+
- const C
174+
- r *http.Request
175+
- w http.ResponseWriter
176+
- T any
177+
- m map[string]int
178+
179+
# Enable only fast linters from enabled linters set (first run won't be fast)
180+
# Default: false
181+
fast: false
182+
183+
formatters:
184+
enable:
185+
# - gci
186+
- gofumpt
187+
- goimports
188+
# - golines
189+
# gci:
190+
# # Section configuration to compare against.
191+
# # Section names are case-insensitive and may contain parameters in ().
192+
# # The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
193+
# # If `custom-order` is `true`, it follows the order of `sections` option.
194+
# # Default: ["standard", "default"]
195+
# sections:
196+
# - standard # Standard section: captures all standard packages.
197+
# - default # Default section: contains all imports that could not be matched to another section type.
198+
# - prefix(github.com/hyp3rd/ewrap) # Custom section: groups all imports with the specified Prefix.
199+
# # Checks that no inline comments are present.
200+
# # Default: false
201+
# no-inline-comments: false
202+
# # Checks that no prefix comments (comment lines above an import) are present.
203+
# # Default: false
204+
# no-prefix-comments: false
205+
# # Enable custom order of sections.
206+
# # If `true`, make the section order the same as the order of `sections`.
207+
# # Default: false
208+
# custom-order: true
209+
# # Drops lexical ordering for custom sections.
210+
# # Default: false
211+
# no-lex-order: false
212+
213+
goimports:
214+
# A comma-separated list of prefixes, which, if set, checks import paths
215+
# with the given prefixes are grouped after 3rd-party packages.
216+
# Default: ""
217+
local-prefixes: github.com/hyp3rd/ewrap
218+
219+
gofmt:
220+
gofumpt:
221+
# Module path which contains the source code being formatted.
222+
# Default: ""
223+
module-path: github.com/hyp3rd/ewrap
224+
# Choose whether to use the extra rules.
225+
# Default: false
226+
extra-rules: true
227+
228+
# output configuration options
229+
output:
230+
# Print lines of code with issue.
231+
# Default: true
232+
print-issued-lines: true
233+
# Print linter name in the end of issue text.
234+
# Default: true
235+
print-linter-name: true
236+
# Add a prefix to the output file references.
237+
# Default: ""
238+
path-prefix: ""
239+
# Sort results by the order defined in `sort-order`.
240+
# Default: false
241+
sort-results: true
242+
# Order to use when sorting results.
243+
# Require `sort-results` to `true`.
244+
# Possible values: `file`, `linter`, and `severity`.
245+
#
246+
# If the severity values are inside the following list, they are ordered in this order:
247+
# 1. error
248+
# 2. warning
249+
# 3. high
250+
# 4. medium
251+
# 5. low
252+
# Either they are sorted alphabetically.
253+
#
254+
# Default: ["file"]
255+
sort-order:
256+
- linter
257+
- severity
258+
- file # filepath, line, and column.
259+
# Show statistics per linter.
260+
# Default: false
261+
show-stats: true
262+
263+
issues:
264+
# Make issues output unique by line.
265+
# Default: true
266+
uniq-by-line: false

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v6.0.0
5+
hooks:
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: mixed-line-ending
9+
- id: fix-byte-order-marker
10+
- id: check-executables-have-shebangs
11+
- id: check-merge-conflict
12+
- id: debug-statements
13+
- id: check-yaml
14+
files: .*\.(yaml|yml)$
15+
exclude: docs/*
16+
args: [--allow-multiple-documents]
17+
- repo: https://github.com/adrienverge/yamllint.git
18+
rev: v1.37.1
19+
hooks:
20+
- id: yamllint
21+
files: \.(yaml|yml)$
22+
types: [file, yaml]
23+
entry: yamllint -c ./.yamllint.yaml --strict -f parsable
24+
- repo: local
25+
hooks:
26+
- id: golangci-lint
27+
name: golangci-lint
28+
language: system
29+
entry: ./.pre-commit/golangci-lint-hook
30+
require_serial: true
31+
- id: unit-test
32+
name: unit test
33+
language: system
34+
entry: ./.pre-commit/unit-test-hook
35+
require_serial: true

.pre-commit/golangci-lint-hook

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# ######################################
5+
# Ensure that a go module is initialized if not, skip the tests
6+
# #######################################
7+
ensure_go_module_initialized() {
8+
if [[ ! -f go.mod ]]; then
9+
echo "go.mod file not found, skipping the tests..."
10+
exit 0
11+
fi
12+
}
13+
14+
# #######################################
15+
# Constants
16+
# #######################################
17+
GO_BIN_PATH="$(go env GOPATH)/bin"
18+
GOLANGCI_LINT_INSTALL_URL="https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh"
19+
GOLANGCI_LINT_VERSION="v2.4.0"
20+
21+
# #######################################
22+
# Install dependencies to run the pre-commit hook
23+
# #######################################
24+
install_dependencies() {
25+
# check if golangci-lint is installed or not
26+
if ! command -v golangci-lint >/dev/null 2>&1; then
27+
echo "installing golangci-lint ${GOLANGCI_LINT_VERSION}..."
28+
29+
# binary will be $(go env GOPATH)/bin/golangci-lint
30+
curl -sSfL "${GOLANGCI_LINT_INSTALL_URL}" | sh -s -- -b "$(go env GOPATH)/bin" "${GOLANGCI_LINT_VERSION}"
31+
32+
echo "Installed golangci-lint ${GOLANGCI_LINT_VERSION}"
33+
34+
"$(go env GOPATH)"/bin/golangci-lint --version
35+
36+
# export the golangci-lint path to the PATH variable
37+
export PATH="${GO_BIN_PATH}:${PATH}"
38+
else
39+
echo "golangci-lint is already installed"
40+
fi
41+
}
42+
43+
# #######################################
44+
# Run the pre-commit
45+
# #######################################
46+
hook() {
47+
install_dependencies
48+
49+
# get the root of the project
50+
local root_dir
51+
root_dir=$(git rev-parse --show-toplevel)
52+
53+
# run the pre-commit hook
54+
pushd "${root_dir}" || exit
55+
56+
echo "Running golangci-lint..."
57+
golangci-lint run ./... || exit 1
58+
59+
popd >/dev/null || exit
60+
}
61+
62+
cat <<EOF
63+
golangci-lint hook
64+
=============================================================================
65+
66+
This hook ensures and runs golangci-lint on the project.
67+
It should be installed and run as a pre-commit hook.
68+
69+
If golangci-lint finds any errors it will prevent the commit.
70+
=============================================================================
71+
72+
EOF
73+
74+
# run the hook if the go module is initialized
75+
ensure_go_module_initialized
76+
hook

0 commit comments

Comments
 (0)