Skip to content

Commit 4fea64e

Browse files
authored
Merge branch 'main' into fix-http-upstreams-keepalive
2 parents 82d718a + 052c7d8 commit 4fea64e

File tree

5 files changed

+50
-43
lines changed

5 files changed

+50
-43
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "CodeQL"
1+
name: CodeQL
22

33
on:
44
push:
@@ -23,55 +23,49 @@ jobs:
2323
name: Analyze
2424
runs-on: ubuntu-22.04
2525
permissions:
26-
actions: read
27-
contents: read
28-
security-events: write
26+
actions: read # for github/codeql-action/init to get workflow details
27+
contents: read # for actions/checkout to fetch code
28+
security-events: write # for github/codeql-action/autobuild to send a status report
29+
packages: read # required to fetch internal or private CodeQL packs
2930

3031
strategy:
3132
fail-fast: false
3233
matrix:
33-
language: ["go"]
34-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
35-
# Use only 'java' to analyze code written in Java, Kotlin or both
36-
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
37-
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
34+
include:
35+
- language: go
36+
build-mode: autobuild
37+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
38+
# Use `c-cpp` to analyze code written in C, C++ or both
39+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
40+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
41+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
42+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
43+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
44+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
3845

3946
steps:
4047
- name: Checkout repository
4148
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4249

50+
- name: Setup Golang Environment
51+
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
52+
with:
53+
go-version: stable
54+
if: matrix.language == 'go'
55+
4356
# Initializes the CodeQL tools for scanning.
4457
- name: Initialize CodeQL
4558
uses: github/codeql-action/init@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
4659
with:
4760
languages: ${{ matrix.language }}
61+
build-mode: ${{ matrix.build-mode }}
4862
# If you wish to specify custom queries, you can do so here or in a config file.
4963
# By default, queries listed here will override any specified in a config file.
5064
# Prefix the list here with "+" to use these queries and those in the config file.
5165

5266
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
5367
# queries: security-extended,security-and-quality
5468

55-
- name: Setup Golang Environment
56-
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
57-
with:
58-
go-version: stable
59-
60-
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
61-
# If this step fails, then you should remove it and run the build manually (see below)
62-
- name: Autobuild
63-
uses: github/codeql-action/autobuild@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
64-
65-
# ℹ️ Command-line programs to run using the OS shell.
66-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67-
68-
# If the Autobuild fails above, remove it and uncomment the following three lines.
69-
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70-
71-
# - run: |
72-
# echo "Run, Build Application using script"
73-
# ./location_of_script_within_repo/buildscript.sh
74-
7569
- name: Perform CodeQL Analysis
7670
uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
7771
with:

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ linters:
3434
- asasalint
3535
- asciicheck
3636
- bidichk
37+
- contextcheck
3738
- dupword
39+
- durationcheck
3840
- errcheck
41+
- errchkjson
3942
- errname
4043
- errorlint
4144
- exportloopref
4245
- fatcontext
4346
- forcetypeassert
4447
- gocheckcompilerdirectives
48+
- gochecksumtype
49+
- gocritic
4550
- godot
4651
- gofmt
4752
- gofumpt
@@ -54,6 +59,7 @@ linters:
5459
- intrange
5560
- makezero
5661
- misspell
62+
- musttag
5763
- nilerr
5864
- noctx
5965
- nolintlint

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ repos:
3333
hooks:
3434
- id: markdownlint-cli2
3535

36+
- repo: https://github.com/adrienverge/yamllint.git
37+
rev: v1.35.1
38+
hooks:
39+
- id: yamllint
40+
3641
ci:
3742
skip: [golangci-lint-full]

client/nginx.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ type StreamUpstreamServer struct {
8383
}
8484

8585
type apiErrorResponse struct {
86-
RequestID string `json:"request_id"`
87-
Href string
88-
Error apiError
86+
RequestID string `json:"request_id"`
87+
Href string `json:"href"`
88+
Error apiError `json:"error"`
8989
}
9090

9191
func (resp *apiErrorResponse) toString() string {
@@ -94,9 +94,9 @@ func (resp *apiErrorResponse) toString() string {
9494
}
9595

9696
type apiError struct {
97-
Text string
98-
Code string
99-
Status int
97+
Text string `json:"text"`
98+
Code string `json:"code"`
99+
Status int `json:"status"`
100100
}
101101

102102
type internalError struct {

client/nginx_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,20 @@ func TestClientWithHTTPClient(t *testing.T) {
602602
func TestGetStats_NoStreamEndpoint(t *testing.T) {
603603
t.Parallel()
604604
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
605-
if r.RequestURI == "/" {
605+
switch {
606+
case r.RequestURI == "/":
606607
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
607608
if err != nil {
608609
t.Fatalf("unexpected error: %v", err)
609610
}
610-
} else if r.RequestURI == "/7/" {
611+
case r.RequestURI == "/7/":
611612
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl"]`))
612613
if err != nil {
613614
t.Fatalf("unexpected error: %v", err)
614615
}
615-
} else if strings.HasPrefix(r.RequestURI, "/7/stream") {
616+
case strings.HasPrefix(r.RequestURI, "/7/stream"):
616617
t.Fatal("Stream endpoint should not be called since it does not exist.")
617-
} else {
618+
default:
618619
_, err := w.Write([]byte(`{}`))
619620
if err != nil {
620621
t.Fatalf("unexpected error: %v", err)
@@ -654,17 +655,18 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
654655
func TestGetStats_SSL(t *testing.T) {
655656
t.Parallel()
656657
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
657-
if r.RequestURI == "/" {
658+
switch {
659+
case r.RequestURI == "/":
658660
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
659661
if err != nil {
660662
t.Fatalf("unexpected error: %v", err)
661663
}
662-
} else if r.RequestURI == "/8/" {
664+
case r.RequestURI == "/8/":
663665
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl","workers"]`))
664666
if err != nil {
665667
t.Fatalf("unexpected error: %v", err)
666668
}
667-
} else if strings.HasPrefix(r.RequestURI, "/8/ssl") {
669+
case strings.HasPrefix(r.RequestURI, "/8/ssl"):
668670
_, err := w.Write([]byte(`{
669671
"handshakes" : 79572,
670672
"handshakes_failed" : 21025,
@@ -684,7 +686,7 @@ func TestGetStats_SSL(t *testing.T) {
684686
if err != nil {
685687
t.Fatalf("unexpected error: %v", err)
686688
}
687-
} else {
689+
default:
688690
_, err := w.Write([]byte(`{}`))
689691
if err != nil {
690692
t.Fatalf("unexpected error: %v", err)

0 commit comments

Comments
 (0)