mirror of
https://github.com/foomo/contentfulproxy.git
synced 2025-10-16 12:25:37 +00:00
fix: lint issues
This commit is contained in:
parent
5b588c4ab2
commit
8a412bcec6
@ -1,15 +1,12 @@
|
|||||||
# EditorConfig is awesome: https://EditorConfig.org
|
|
||||||
|
|
||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
end_of_line = lf
|
|
||||||
|
|
||||||
[*.{yaml,yml}]
|
[*.{yaml,yml,md,mdx}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
|||||||
181
.gitignore
vendored
181
.gitignore
vendored
@ -1,172 +1,11 @@
|
|||||||
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
|
.*
|
||||||
|
*.log
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,go,jetbrains+all
|
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,go,jetbrains+all
|
|
||||||
|
|
||||||
### Go ###
|
|
||||||
# Binaries for programs and plugins
|
|
||||||
*.exe
|
|
||||||
*.exe~
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
|
||||||
*.test
|
|
||||||
|
|
||||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
|
||||||
*.out
|
*.out
|
||||||
|
!.github/
|
||||||
# Dependency directories (remove the comment below to include it)
|
!.husky/
|
||||||
# vendor/
|
!.editorconfig
|
||||||
|
!.gitignore
|
||||||
### Go Patch ###
|
!.golangci.yml
|
||||||
/vendor/
|
!.goreleaser.yml
|
||||||
/Godeps/
|
!.husky.yaml
|
||||||
|
/tmp/
|
||||||
### JetBrains+all ###
|
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/**/usage.statistics.xml
|
|
||||||
.idea/**/dictionaries
|
|
||||||
.idea/**/shelf
|
|
||||||
|
|
||||||
# AWS User-specific
|
|
||||||
.idea/**/aws.xml
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
.idea/**/contentModel.xml
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
.idea/**/dataSources/
|
|
||||||
.idea/**/dataSources.ids
|
|
||||||
.idea/**/dataSources.local.xml
|
|
||||||
.idea/**/sqlDataSources.xml
|
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
.idea/**/dbnavigator.xml
|
|
||||||
|
|
||||||
# Gradle
|
|
||||||
.idea/**/gradle.xml
|
|
||||||
.idea/**/libraries
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
cmake-build-*/
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
.idea/replstate.xml
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
.idea/httpRequests
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
.idea/caches/build_file_checksums.ser
|
|
||||||
|
|
||||||
### JetBrains+all Patch ###
|
|
||||||
# Ignores the whole .idea folder and all .iml files
|
|
||||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
|
||||||
|
|
||||||
.idea/
|
|
||||||
|
|
||||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
|
||||||
|
|
||||||
*.iml
|
|
||||||
modules.xml
|
|
||||||
.idea/misc.xml
|
|
||||||
*.ipr
|
|
||||||
|
|
||||||
# Sonarlint plugin
|
|
||||||
.idea/sonarlint
|
|
||||||
|
|
||||||
### macOS ###
|
|
||||||
# General
|
|
||||||
.DS_Store
|
|
||||||
.AppleDouble
|
|
||||||
.LSOverride
|
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
|
|
||||||
# Thumbnails
|
|
||||||
._*
|
|
||||||
|
|
||||||
# Files that might appear in the root of a volume
|
|
||||||
.DocumentRevisions-V100
|
|
||||||
.fseventsd
|
|
||||||
.Spotlight-V100
|
|
||||||
.TemporaryItems
|
|
||||||
.Trashes
|
|
||||||
.VolumeIcon.icns
|
|
||||||
.com.apple.timemachine.donotpresent
|
|
||||||
|
|
||||||
# Directories potentially created on remote AFP share
|
|
||||||
.AppleDB
|
|
||||||
.AppleDesktop
|
|
||||||
Network Trash Folder
|
|
||||||
Temporary Items
|
|
||||||
.apdisk
|
|
||||||
|
|
||||||
### VisualStudioCode ###
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
*.code-workspace
|
|
||||||
|
|
||||||
# Local History for Visual Studio Code
|
|
||||||
.history/
|
|
||||||
|
|
||||||
### VisualStudioCode Patch ###
|
|
||||||
# Ignore all local history of files
|
|
||||||
.history
|
|
||||||
.ionide
|
|
||||||
|
|
||||||
# Support for Project snippet scope
|
|
||||||
!.vscode/*.code-snippets
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,go,jetbrains+all
|
|
||||||
|
|
||||||
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
|
||||||
|
|
||||||
bin/*
|
|
||||||
!bin/.gitkeep
|
|
||||||
|
|||||||
252
.golangci.yml
252
.golangci.yml
@ -1,89 +1,191 @@
|
|||||||
run:
|
run:
|
||||||
timeout: 5m
|
timeout: 5m
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-dirs:
|
||||||
|
- 'bin'
|
||||||
|
- 'tmp'
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- noctx
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
gci:
|
# https://golangci-lint.run/usage/linters/#misspell
|
||||||
local-prefixes: github.com/foomo/squadron
|
misspell:
|
||||||
golint:
|
mode: restricted
|
||||||
min-confidence: 0
|
# https://golangci-lint.run/usage/linters/#asasalint
|
||||||
goimports:
|
asasalint:
|
||||||
local-prefixes: github.com/foomo/squadron
|
ignore-test: true
|
||||||
|
# https://golangci-lint.run/usage/linters/#exhaustive
|
||||||
|
exhaustive:
|
||||||
|
default-signifies-exhaustive: true
|
||||||
|
# https://golangci-lint.run/usage/linters/#gocritic
|
||||||
|
gocritic:
|
||||||
|
disabled-checks:
|
||||||
|
- assignOp
|
||||||
|
- ifElseChain
|
||||||
|
# https://golangci-lint.run/usage/linters/#testifylint
|
||||||
|
testifylint:
|
||||||
|
disable:
|
||||||
|
- float-compare
|
||||||
|
# https://golangci-lint.run/usage/linters/#gosec
|
||||||
|
gosec:
|
||||||
|
confidence: medium
|
||||||
|
# https://golangci-lint.run/usage/linters/#revive
|
||||||
revive:
|
revive:
|
||||||
|
enable-all-rules: true
|
||||||
|
ignore-generated-header: true
|
||||||
rules:
|
rules:
|
||||||
|
- name: line-length-limit
|
||||||
|
disabled: true
|
||||||
|
- name: cognitive-complexity
|
||||||
|
disabled: true
|
||||||
|
- name: unused-parameter
|
||||||
|
disabled: true
|
||||||
|
- name: add-constant
|
||||||
|
disabled: true
|
||||||
- name: indent-error-flow
|
- name: indent-error-flow
|
||||||
disabled: true
|
disabled: true
|
||||||
gocritic:
|
- name: cyclomatic
|
||||||
enabled-tags:
|
disabled: true
|
||||||
- diagnostic
|
- name: function-length
|
||||||
- style
|
disabled: true
|
||||||
disabled-tags:
|
- name: use-any
|
||||||
- performance
|
disabled: true
|
||||||
- experimental
|
- name: max-public-structs
|
||||||
- opinionated
|
disabled: true
|
||||||
lll:
|
- name: function-result-limit
|
||||||
line-length: 200
|
disabled: true
|
||||||
|
- name: flag-parameter
|
||||||
|
disabled: true
|
||||||
|
- name: unused-receiver
|
||||||
|
disabled: true
|
||||||
|
- name: argument-limit
|
||||||
|
disabled: true
|
||||||
|
- name: empty-lines
|
||||||
|
disabled: true
|
||||||
|
- name: confusing-results
|
||||||
|
disabled: true
|
||||||
|
- name: max-control-nesting
|
||||||
|
disabled: true
|
||||||
|
- name: comment-spacings
|
||||||
|
disabled: true
|
||||||
|
- name: struct-tag
|
||||||
|
arguments:
|
||||||
|
- "json,inline"
|
||||||
|
- name: unhandled-error
|
||||||
|
arguments:
|
||||||
|
- "fmt.Printf"
|
||||||
|
- "fmt.Println"
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
## Enabled by default linters:
|
||||||
- deadcode
|
- errcheck # errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
|
||||||
- dogsled
|
- gosimple # (megacheck) Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false]
|
||||||
- exhaustive
|
- govet # (vet, vetshadow) Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes. [fast: false, auto-fix: false]
|
||||||
- exportloopref
|
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
|
||||||
- goconst
|
- staticcheck # (megacheck) It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false]
|
||||||
- gofmt
|
- unused # (megacheck) Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
|
||||||
- gofumpt
|
|
||||||
- goimports
|
|
||||||
- revive
|
|
||||||
- goprintffuncname
|
|
||||||
- govet
|
|
||||||
- ineffassign
|
|
||||||
- misspell
|
|
||||||
- nakedret
|
|
||||||
- nolintlint
|
|
||||||
- prealloc
|
|
||||||
- rowserrcheck
|
|
||||||
- sqlclosecheck
|
|
||||||
- staticcheck
|
|
||||||
- structcheck
|
|
||||||
- stylecheck
|
|
||||||
- typecheck
|
|
||||||
- unconvert
|
|
||||||
- unparam
|
|
||||||
- unused
|
|
||||||
- varcheck
|
|
||||||
- whitespace
|
|
||||||
- errcheck
|
|
||||||
- gocritic
|
|
||||||
- gosimple
|
|
||||||
|
|
||||||
- gocyclo
|
## Disabled by your configuration linters:
|
||||||
- gosec
|
- asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false]
|
||||||
- lll
|
- asciicheck # checks that all code identifiers does not have non-ASCII symbols in the name [fast: true, auto-fix: false]
|
||||||
- exportloopref
|
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
|
||||||
|
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
|
||||||
|
#- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: false, auto-fix: false]
|
||||||
|
#- contextcheck # check whether the function uses a non-inherited context [fast: false, auto-fix: false]
|
||||||
|
- copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false]
|
||||||
|
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
|
||||||
|
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
|
||||||
|
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
|
||||||
|
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
|
||||||
|
- 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. [fast: false, auto-fix: false]
|
||||||
|
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
|
||||||
|
#- forbidigo # Forbids identifiers [fast: false, auto-fix: false]
|
||||||
|
- forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
|
||||||
|
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false]
|
||||||
|
- gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false]
|
||||||
|
#- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
|
||||||
|
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: true]
|
||||||
|
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
|
||||||
|
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: true]
|
||||||
|
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode. [fast: true, auto-fix: true]
|
||||||
|
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
|
||||||
|
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
|
||||||
|
- goprintffuncname # Checks that printf-like functions are named with `f` at the end. [fast: true, auto-fix: false]
|
||||||
|
- gosec # (gas) Inspects source code for security problems [fast: false, auto-fix: false]
|
||||||
|
#- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase [fast: false, auto-fix: false]
|
||||||
|
- grouper # Analyze expression groups. [fast: true, auto-fix: false]
|
||||||
|
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
|
||||||
|
#- inamedparam # reports interfaces with unnamed method parameters [fast: true, auto-fix: false]
|
||||||
|
#- intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
|
||||||
|
#- loggercheck # (logrlint) Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). [fast: false, auto-fix: false]
|
||||||
|
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
|
||||||
|
- misspell # Finds commonly misspelled English words [fast: true, auto-fix: true]
|
||||||
|
- mirror # reports wrong mirror patterns of bytes/strings usage [fast: false, auto-fix: true]
|
||||||
|
- musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false]
|
||||||
|
#- nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). [fast: true, auto-fix: false]
|
||||||
|
- nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
|
||||||
|
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
|
||||||
|
#- noctx # Finds sending http request without context.Context [fast: false, auto-fix: false]
|
||||||
|
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: true]
|
||||||
|
- nonamedreturns # Reports all named returns [fast: false, auto-fix: false]
|
||||||
|
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
|
||||||
|
#- paralleltest # Detects missing usage of t.Parallel() method in your Go test [fast: false, auto-fix: false]
|
||||||
|
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
|
||||||
|
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
|
||||||
|
- reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false]
|
||||||
|
#- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
|
||||||
|
- rowserrcheck # checks whether Rows.Err of rows is checked successfully [fast: false, auto-fix: false]
|
||||||
|
- spancheck # Checks for mistakes with OpenTelemetry/Census spans. [fast: false, auto-fix: false]
|
||||||
|
- sqlclosecheck # Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed. [fast: false, auto-fix: false]
|
||||||
|
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
|
||||||
|
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
|
||||||
|
- testableexamples # linter checks if examples are testable (have an expected output) [fast: true, auto-fix: false]
|
||||||
|
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
|
||||||
|
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
|
||||||
|
- thelper # thelper detects tests helpers which is not start with t.Helper() method. [fast: false, auto-fix: false]
|
||||||
|
#- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. [fast: false, auto-fix: false]
|
||||||
|
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
|
||||||
|
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
|
||||||
|
- wastedassign # Finds wasted assignment statements [fast: false, auto-fix: false]
|
||||||
|
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. [fast: true, auto-fix: true]
|
||||||
|
|
||||||
# unused
|
## Don't enable
|
||||||
# - gci
|
#- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
|
||||||
# - noctx
|
#- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
|
||||||
# - dupl
|
#- dupl # Tool for code clone detection [fast: true, auto-fix: false]
|
||||||
# - godot
|
#- dupword # checks for duplicate words in the source code [fast: true, auto-fix: false]
|
||||||
# - gocognit
|
#- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
|
||||||
# - nlreturn
|
#- err113 # Go linter to check the errors handling expressions [fast: false, auto-fix: false]
|
||||||
# - gochecknoglobals
|
#- exhaustruct # Checks if all structure fields are initialized [fast: false, auto-fix: false]
|
||||||
# - gochecknoinits
|
#- gci # Gci controls Go package import order and makes it always deterministic. [fast: true, auto-fix: true]
|
||||||
# - depguard
|
#- gochecknoglobals # Check that no global variables exist. [fast: false, auto-fix: false]
|
||||||
# - goheader
|
#- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
|
||||||
# - gomodguard
|
#- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
|
||||||
|
#- godot # Check if comments end in a period [fast: true, auto-fix: true]
|
||||||
# don't enable:
|
#- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
|
||||||
# - asciicheck
|
#- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
|
||||||
# - funlen
|
#- funlen # Tool for detection of long functions [fast: true, auto-fix: false]
|
||||||
# - godox
|
#- ginkgolinter # enforces standards of using ginkgo and gomega [fast: false, auto-fix: false]
|
||||||
# - goerr113
|
#- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
|
||||||
# - gomnd
|
#- interfacebloat # A linter that checks the number of methods inside an interface. [fast: true, auto-fix: false]
|
||||||
# - interfacer
|
#- lll # Reports long lines [fast: true, auto-fix: false]
|
||||||
# - maligned
|
#- ireturn # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false]
|
||||||
# - nestif
|
#- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
|
||||||
# - testpackage
|
#- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
|
||||||
# - wsl
|
#- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
|
||||||
|
#- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [fast: false, auto-fix: false]
|
||||||
|
#- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
|
||||||
|
#- protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true]
|
||||||
|
#- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false]
|
||||||
|
#- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true]
|
||||||
|
#- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
|
||||||
|
#- unparam # Reports unused function parameters [fast: false, auto-fix: false]
|
||||||
|
#- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
|
||||||
|
#- wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
|
||||||
|
#- wsl # add or remove empty lines [fast: true, auto-fix: false]
|
||||||
|
#- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/foomo/keel"
|
"github.com/foomo/keel"
|
||||||
"github.com/foomo/keel/log"
|
"github.com/foomo/keel/log"
|
||||||
"github.com/foomo/keel/net/http/middleware"
|
"github.com/foomo/keel/net/http/middleware"
|
||||||
|
"github.com/foomo/keel/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -34,32 +35,30 @@ func main() {
|
|||||||
backendURL := config.DefaultBackendURL(c)
|
backendURL := config.DefaultBackendURL(c)
|
||||||
|
|
||||||
// create proxy
|
// create proxy
|
||||||
proxy, _ := proxy.NewProxy(
|
p, err := proxy.NewProxy(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
log.WithServiceName(l, ServiceName),
|
log.WithServiceName(l, ServiceName),
|
||||||
backendURL,
|
backendURL,
|
||||||
webserverPath,
|
webserverPath,
|
||||||
webhookURLs,
|
webhookURLs,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
l.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// add the service to keel
|
// add the service to keel
|
||||||
svr.AddServices(
|
svr.AddServices(
|
||||||
keel.NewServiceHTTP(
|
service.NewHTTP(
|
||||||
log.WithServiceName(l, ServiceName),
|
log.WithServiceName(l, ServiceName),
|
||||||
ServiceName,
|
ServiceName,
|
||||||
webserverAddress(),
|
webserverAddress(),
|
||||||
proxy,
|
p,
|
||||||
getMiddleWares()...,
|
middleware.Logger(),
|
||||||
|
middleware.Telemetry(),
|
||||||
|
middleware.RequestID(),
|
||||||
|
middleware.Recover(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
svr.Run()
|
svr.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMiddleWares() []middleware.Middleware {
|
|
||||||
return []middleware.Middleware{
|
|
||||||
middleware.Logger(),
|
|
||||||
middleware.Telemetry(),
|
|
||||||
middleware.RequestID(),
|
|
||||||
middleware.Recover(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
172
go.mod
172
go.mod
@ -1,68 +1,128 @@
|
|||||||
module github.com/foomo/contentfulproxy
|
module github.com/foomo/contentfulproxy
|
||||||
|
|
||||||
go 1.17
|
go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/foomo/keel v0.3.1
|
github.com/foomo/keel v0.19.1
|
||||||
github.com/prometheus/client_golang v1.10.0
|
github.com/prometheus/client_golang v1.20.5
|
||||||
github.com/spf13/viper v1.7.1
|
github.com/spf13/viper v1.19.0
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.10.0
|
||||||
go.uber.org/zap v1.19.1
|
go.uber.org/zap v1.27.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
cloud.google.com/go v0.112.1 // indirect
|
||||||
|
cloud.google.com/go/compute/metadata v0.5.0 // indirect
|
||||||
|
cloud.google.com/go/firestore v1.15.0 // indirect
|
||||||
|
cloud.google.com/go/longrunning v0.5.5 // indirect
|
||||||
|
github.com/armon/go-metrics v0.4.1 // indirect
|
||||||
|
github.com/avast/retry-go/v4 v4.6.0 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.1 // indirect
|
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/felixge/httpsnoop v1.0.1 // indirect
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.4.7 // indirect
|
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
|
github.com/ebitengine/purego v0.8.1 // indirect
|
||||||
|
github.com/fatih/color v1.14.1 // indirect
|
||||||
|
github.com/fbiville/markdown-table-formatter v0.3.0 // indirect
|
||||||
|
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||||
|
github.com/foomo/gostandards v0.2.0 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||||
github.com/golang/protobuf v1.5.0 // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/google/uuid v1.1.2 // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
github.com/google/s2a-go v0.1.7 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
|
||||||
|
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
|
||||||
|
github.com/hashicorp/consul/api v1.28.2 // indirect
|
||||||
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
|
github.com/hashicorp/go-hclog v1.5.0 // indirect
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
|
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/magiconair/properties v1.8.1 // indirect
|
github.com/hashicorp/serf v0.10.1 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.1.2 // indirect
|
github.com/klauspost/compress v1.17.11 // indirect
|
||||||
github.com/pelletier/go-toml v1.7.0 // indirect
|
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
github.com/nats-io/nats.go v1.37.0 // indirect
|
||||||
|
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||||
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
|
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
||||||
github.com/prometheus/common v0.18.0 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/procfs v0.6.0 // indirect
|
github.com/prometheus/common v0.60.1 // indirect
|
||||||
github.com/shirou/gopsutil v2.20.9+incompatible // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/spf13/afero v1.1.2 // indirect
|
github.com/sagikazarmark/crypt v0.19.0 // indirect
|
||||||
github.com/spf13/cast v1.3.0 // indirect
|
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.0.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.3 // indirect
|
github.com/shirou/gopsutil/v4 v4.24.10 // indirect
|
||||||
github.com/subosito/gotenv v1.2.0 // indirect
|
github.com/sony/gobreaker v1.0.0 // indirect
|
||||||
go.opentelemetry.io/contrib v0.20.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/host v0.20.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
|
github.com/spf13/cast v1.6.0 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.20.0 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
go.opentelemetry.io/otel v0.20.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/metric/prometheus v0.20.0 // indirect
|
github.com/tinylib/msgp v1.2.4 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
|
github.com/tklauser/go-sysconf v0.3.14 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/stdout v0.20.0 // indirect
|
github.com/tklauser/numcpus v0.9.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v0.20.0 // indirect
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
go.opentelemetry.io/otel/sdk v0.20.0 // indirect
|
go.etcd.io/etcd/api/v3 v3.5.12 // indirect
|
||||||
go.opentelemetry.io/otel/sdk/export/metric v0.20.0 // indirect
|
go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect
|
||||||
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
|
go.etcd.io/etcd/client/v2 v2.305.12 // indirect
|
||||||
go.opentelemetry.io/otel/trace v0.20.0 // indirect
|
go.etcd.io/etcd/client/v3 v3.5.12 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
|
go.opencensus.io v0.24.0 // indirect
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/host v0.57.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
|
go.opentelemetry.io/contrib/instrumentation/runtime v0.57.0 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
go.opentelemetry.io/otel v1.32.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
|
||||||
golang.org/x/text v0.3.6 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.32.0 // indirect
|
||||||
google.golang.org/grpc v1.37.0 // indirect
|
go.opentelemetry.io/otel/exporters/prometheus v0.54.0 // indirect
|
||||||
google.golang.org/protobuf v1.26.0 // indirect
|
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.32.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.51.0 // indirect
|
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.32.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
go.opentelemetry.io/otel/metric v1.32.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
|
||||||
|
go.opentelemetry.io/otel/trace v1.32.0 // indirect
|
||||||
|
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
|
||||||
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
golang.org/x/crypto v0.29.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
|
||||||
|
golang.org/x/net v0.30.0 // indirect
|
||||||
|
golang.org/x/oauth2 v0.23.0 // indirect
|
||||||
|
golang.org/x/sync v0.9.0 // indirect
|
||||||
|
golang.org/x/sys v0.27.0 // indirect
|
||||||
|
golang.org/x/text v0.20.0 // indirect
|
||||||
|
golang.org/x/time v0.5.0 // indirect
|
||||||
|
google.golang.org/api v0.171.0 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||||
|
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
|
||||||
|
google.golang.org/grpc v1.68.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.35.1 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5" // nolint:gosec
|
"crypto/md5" //nolint:gosec
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -31,7 +31,7 @@ type Cache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) set(id cacheID, response *http.Response) (*cachedResponse, error) {
|
func (c *Cache) set(id cacheID, response *http.Response) (*cachedResponse, error) {
|
||||||
responseBytes, err := ioutil.ReadAll(response.Body)
|
responseBytes, err := io.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func (c *Cache) callWebHooks() {
|
|||||||
for _, url := range c.webHooks() {
|
for _, url := range c.webHooks() {
|
||||||
go func(url string, l *zap.Logger) {
|
go func(url string, l *zap.Logger) {
|
||||||
l.Info("call webhook")
|
l.Info("call webhook")
|
||||||
resp, err := http.Get(url) // nolint:gosec
|
resp, err := http.Get(url) //nolint:gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Error("error while calling webhook", zap.Error(err))
|
l.Error("error while calling webhook", zap.Error(err))
|
||||||
}
|
}
|
||||||
@ -102,8 +102,8 @@ func getCacheIDForRequest(r *http.Request, pathPrefix func() string) cacheID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// hash it here maybe, to keep it shorter
|
// hash it here maybe, to keep it shorter
|
||||||
hash := md5.New() // nolint:gosec
|
hash := md5.New() //nolint:gosec
|
||||||
hash.Write([]byte(id))
|
_, _ = hash.Write([]byte(id))
|
||||||
id = hex.EncodeToString(hash.Sum(nil))
|
id = hex.EncodeToString(hash.Sum(nil))
|
||||||
return cacheID(id)
|
return cacheID(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func getJobRunner(l *zap.Logger, c *Cache, backendURL func() string, pathPrefix
|
|||||||
// backend url is the contentful api domain like https://cdn.contenful.com
|
// backend url is the contentful api domain like https://cdn.contenful.com
|
||||||
calledURL := backendURL() + stripPrefixFromURL(job.request.URL.RequestURI(), pathPrefix)
|
calledURL := backendURL() + stripPrefixFromURL(job.request.URL.RequestURI(), pathPrefix)
|
||||||
l.Info("URL called by job-runner", log.FURL(calledURL))
|
l.Info("URL called by job-runner", log.FURL(calledURL))
|
||||||
req, err := http.NewRequest("GET", calledURL, nil)
|
req, err := http.NewRequestWithContext(job.request.Context(), http.MethodGet, calledURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chanJobDone <- requestJobDone{
|
chanJobDone <- requestJobDone{
|
||||||
id: id,
|
id: id,
|
||||||
|
|||||||
@ -109,7 +109,7 @@ func NewProxy(ctx context.Context, l *zap.Logger, backendURL func() string, path
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoop(
|
func getLoop( //nolint:revive
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
l *zap.Logger,
|
l *zap.Logger,
|
||||||
backendURL func() string,
|
backendURL func() string,
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
package proxy
|
package proxy_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/foomo/contentfulproxy/proxy"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"go.uber.org/zap"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -22,8 +24,8 @@ const (
|
|||||||
|
|
||||||
type getStats func(path string) int
|
type getStats func(path string) int
|
||||||
|
|
||||||
//
|
|
||||||
func GetBackend(t *testing.T) (getStats, http.HandlerFunc) {
|
func GetBackend(t *testing.T) (getStats, http.HandlerFunc) {
|
||||||
|
t.Helper()
|
||||||
stats := map[string]int{}
|
stats := map[string]int{}
|
||||||
statLock := sync.RWMutex{}
|
statLock := sync.RWMutex{}
|
||||||
return func(path string) int {
|
return func(path string) int {
|
||||||
@ -54,6 +56,7 @@ func GetBackend(t *testing.T) (getStats, http.HandlerFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetWebHook(t *testing.T) (getStats, http.HandlerFunc) {
|
func GetWebHook(t *testing.T) (getStats, http.HandlerFunc) {
|
||||||
|
t.Helper()
|
||||||
stats := map[string]int{}
|
stats := map[string]int{}
|
||||||
statLock := sync.RWMutex{}
|
statLock := sync.RWMutex{}
|
||||||
return func(path string) int {
|
return func(path string) int {
|
||||||
@ -83,15 +86,16 @@ func GetWebHook(t *testing.T) (getStats, http.HandlerFunc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestServer(t *testing.T) (gs func(path string) int, ws func(path string) int, s *httptest.Server) {
|
func getTestServer(t *testing.T) (func(path string) int, func(path string) int, *httptest.Server) {
|
||||||
l, _ := zap.NewProduction()
|
t.Helper()
|
||||||
|
l := zaptest.NewLogger(t)
|
||||||
|
|
||||||
gs, backendHandler := GetBackend(t)
|
gs, backendHandler := GetBackend(t)
|
||||||
ws, webHookHandler := GetWebHook(t)
|
ws, webHookHandler := GetWebHook(t)
|
||||||
backendServer := httptest.NewServer(backendHandler)
|
backendServer := httptest.NewServer(backendHandler)
|
||||||
webHookServer := httptest.NewServer(webHookHandler)
|
webHookServer := httptest.NewServer(webHookHandler)
|
||||||
|
|
||||||
p, _ := NewProxy(
|
p, _ := proxy.NewProxy(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
l,
|
l,
|
||||||
func() string { return backendServer.URL },
|
func() string { return backendServer.URL },
|
||||||
@ -103,7 +107,7 @@ func getTestServer(t *testing.T) (gs func(path string) int, ws func(path string)
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
s = httptest.NewServer(p)
|
s := httptest.NewServer(p)
|
||||||
t.Log("we have a proxy in front of it running on", s.URL)
|
t.Log("we have a proxy in front of it running on", s.URL)
|
||||||
return gs, ws, s
|
return gs, ws, s
|
||||||
}
|
}
|
||||||
@ -113,10 +117,10 @@ func TestProxy(t *testing.T) {
|
|||||||
|
|
||||||
get := func(path string) string {
|
get := func(path string) string {
|
||||||
resp, err := http.Get(server.URL + path)
|
resp, err := http.Get(server.URL + path)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
responseBytes, err := ioutil.ReadAll(resp.Body)
|
responseBytes, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return string(responseBytes)
|
return string(responseBytes)
|
||||||
}
|
}
|
||||||
for j := 0; j < 10; j++ {
|
for j := 0; j < 10; j++ {
|
||||||
@ -134,11 +138,11 @@ func TestProxy(t *testing.T) {
|
|||||||
|
|
||||||
// check the current status
|
// check the current status
|
||||||
// response, err := http.Get(server.URL + "/info")
|
// response, err := http.Get(server.URL + "/info")
|
||||||
// assert.NoError(t, err)
|
// require.NoError(t, err)
|
||||||
|
|
||||||
//
|
//
|
||||||
resp, err := http.Get(server.URL + "/update")
|
resp, err := http.Get(server.URL + "/update")
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user