Skip to content

Commit fe0ec1e

Browse files
Use oapi-codegen to generate server router (#2322)
Use the oapi-codegen tool to generate a chi-server router to make sure that the openapi spec is the source of truth for fleet-server's interactions. Change how the listeners/routers are created and started, propagate X-Request-Id values in responses, attach and use request specific loggers with additional context for listeners. Changed some of the api spec to allow strings instead of UUIDs Uses a forked version of the oapi-codegen module as some of its dependencies needed to be updated. Uses go-chi/chi and standard net/http patterns instead of httprouter
1 parent 0ecf86b commit fe0ec1e

Some content is hidden

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

49 files changed

+7015
-3419
lines changed

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: golangci/golangci-lint-action@v2
3939
with:
4040
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
41-
version: v1.47.2
41+
version: v1.51.1
4242

4343
# Give the job more time to execute.
4444
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,

.golangci.yml

+17-37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run:
33
# timeout for analysis, e.g. 30s, 5m, default is 1m
44
timeout: 1m
55
build-tags: integration
6+
go: "1.18.10"
67

78
issues:
89
# Maximum count of issues with the same text.
@@ -28,13 +29,12 @@ output:
2829
linters:
2930
disable-all: true
3031
enable:
31-
- deadcode # finds unused code
3232
- errcheck # checking for unchecked errors in go programs
3333
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
3434
- goconst # finds repeated strings that could be replaced by a constant
3535
- dupl # tool for code clone detection
3636
- forbidigo # forbids identifiers matched by reg exps
37-
#- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
37+
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
3838
- gosimple # linter for Go source code that specializes in simplifying a code
3939
- misspell # finds commonly misspelled English words in comments
4040
- nakedret # finds naked returns in functions greater than a specified function length
@@ -48,9 +48,7 @@ linters:
4848
- gomodguard
4949
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
5050
- ineffassign # detects when assignments to existing variables are not used
51-
- structcheck # finds unused struct fields
5251
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
53-
- varcheck # Finds unused global variables and constants
5452
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
5553
- bodyclose # checks whether HTTP response body is closed successfully
5654
- durationcheck # check for two durations multiplied together
@@ -61,8 +59,12 @@ linters:
6159
- nilerr # finds the code that returns nil even if it checks that the error is not nil.
6260
- noctx # noctx finds sending http request without context.Context
6361
- unconvert # Remove unnecessary type conversions
64-
- wastedassign # wastedassign finds wasted assignment statements.
62+
#- wastedassign # wastedassign finds wasted assignment statements. # NOTE disabled due to lack of generics support
6563
#- godox # tool for detection of FIXME, TODO and other comment keywords
64+
- asasalint
65+
- bidichk
66+
- gocheckcompilerdirectives
67+
- tenv
6668

6769

6870
# all available settings of specific linters
@@ -101,28 +103,7 @@ linters-settings:
101103
# Allow local `replace` directives. Default is false.
102104
replace-local: false
103105
replace-allow-list:
104-
- github.com/Shopify/sarama
105-
- github.com/dop251/goja
106-
- github.com/fsnotify/fsevents
107-
108-
gomodguard:
109-
blocked:
110-
# List of blocked modules.
111-
modules:
112-
- github.com/elastic/beats/v7:
113-
reason: "There must be no Beats dependency, use elastic-agent-libs instead."
114-
115-
gosimple:
116-
# Select the Go version to target. The default is '1.13'.
117-
go: "1.18.10"
118-
119-
misspell:
120-
# Correct spellings using locale preferences for US or UK.
121-
# Default is to use a neutral variety of English.
122-
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
123-
# locale: US
124-
# ignore-words:
125-
# - IdP
106+
- github.com/deepmap/oapi-codegen
126107

127108
nakedret:
128109
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
@@ -147,23 +128,22 @@ linters-settings:
147128
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
148129
require-specific: true
149130

150-
staticcheck:
151-
# Select the Go version to target. The default is '1.13'.
152-
go: "1.18.10"
153-
154131
stylecheck:
155-
# Select the Go version to target. The default is '1.13'.
156-
go: "1.18.10"
157132
initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "ECS"]
158133

159-
160134
unparam:
161135
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
162136
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
163137
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
164138
# with golangci-lint call it on a directory with the changed file.
165139
check-exported: false
166140

167-
unused:
168-
# Select the Go version to target. The default is '1.13'.
169-
go: "1.18.10"
141+
gomodguard:
142+
blocked:
143+
# List of blocked modules.
144+
modules:
145+
- github.com/elastic/beats/v7:
146+
reason: "There must be no Beats dependency, use elastic-agent-libs instead."
147+
- github.com/elastic/beats/elastic-agent:
148+
reason: "There must be no elastic-agent dependency, use elastic-agent-libs instead."
149+

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ clean: ## - Clean up build artifacts
6666
generate: ## - Generate schema models
6767
@printf "${CMD_COLOR_ON} Installing module for go generate\n${CMD_COLOR_OFF}"
6868
env GOBIN=${GOBIN} go install github.com/elastic/go-json-schema-generate/cmd/schema-generate@ec19b88f6b5ef7825a928df8274a99337b855d1f
69+
@printf "${CMD_COLOR_ON} Installing module for oapi-codegen\n${CMD_COLOR_OFF}"
70+
env GOBIN=${GOBIN} go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
6971
@printf "${CMD_COLOR_ON} Running go generate\n${CMD_COLOR_OFF}"
7072
env PATH="${GOBIN}:${PATH}" go generate ./...
7173

@@ -88,7 +90,7 @@ check-headers: ## - Check copyright headers
8890

8991
.PHONY: check-go
9092
check-go: ## - Run golangci-lint
91-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/d58dbde584c801091e74a00940e11ff18c6c68bd/install.sh | sh -s v1.47.2
93+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/d58dbde584c801091e74a00940e11ff18c6c68bd/install.sh | sh -s v1.51.1
9294
@./bin/golangci-lint run -v
9395

9496
.PHONY: notice

0 commit comments

Comments
 (0)