chore: update linter

This commit is contained in:
Fernandez Ludovic
2022-11-07 09:50:18 +01:00
parent 64a060b271
commit d40451c79f
10 changed files with 52 additions and 48 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
go-version: [ 1.17, 1.18, 1.x ]
go-version: [ 1.18, 1.19, 1.x ]
os: [ubuntu-latest, macos-latest]
# TODO ignore windows but need to be added in the future
# os: [ubuntu-latest, macos-latest, windows-latest]
+2 -2
View File
@@ -9,8 +9,8 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.17
GOLANGCI_LINT_VERSION: v1.45.2
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.50.1
steps:
+13 -4
View File
@@ -51,12 +51,19 @@ linters-settings:
linters:
enable-all: true
disable:
- maligned # deprecated
- interfacer # deprecated
- scopelint # deprecated
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- cyclop # duplicate of gocyclo
- lll
- dupl
@@ -66,7 +73,7 @@ linters:
- goerr113
- wrapcheck
- exhaustive
- exhaustivestruct
- exhaustruct
- testpackage
- tparallel
- paralleltest
@@ -82,12 +89,14 @@ linters:
- gochecknoglobals # TODO(ldez) should be use on the project
- errorlint # TODO(ldez) should be use on the project
- nestif # TODO(ldez) should be use on the project
- nonamedreturns
issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude:
- 'package-comments: should have a package comment'
- 'Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked'
- 'SA1019: http.CloseNotifier has been deprecated'
- 'string `https` has 3 occurrences, make it a constant'
+21 -23
View File
@@ -7,31 +7,30 @@ Changes request content-transfer-encoding from chunked and provides total size t
Examples of a buffering middleware:
// sample HTTP handler
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
})
// sample HTTP handler.
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
})
// Buffer will read the body in buffer before passing the request to the handler
// calculate total size of the request and transform it from chunked encoding
// before passing to the server
buffer.New(handler)
// Buffer will read the body in buffer before passing the request to the handler
// calculate total size of the request and transform it from chunked encoding
// before passing to the server
buffer.New(handler)
// This version will buffer up to 2MB in memory and will serialize any extra
// to a temporary file, if the request size exceeds 10MB it will reject the request
buffer.New(handler,
buffer.MemRequestBodyBytes(2 * 1024 * 1024),
buffer.MaxRequestBodyBytes(10 * 1024 * 1024))
// This version will buffer up to 2MB in memory and will serialize any extra
// to a temporary file, if the request size exceeds 10MB it will reject the request
buffer.New(handler,
buffer.MemRequestBodyBytes(2 * 1024 * 1024),
buffer.MaxRequestBodyBytes(10 * 1024 * 1024))
// Will do the same as above, but with responses
buffer.New(handler,
buffer.MemResponseBodyBytes(2 * 1024 * 1024),
buffer.MaxResponseBodyBytes(10 * 1024 * 1024))
// Buffer will replay the request if the handler returns error at least 3 times
// before returning the response
buffer.New(handler, buffer.Retry(`IsNetworkError() && Attempts() <= 2`))
// Will do the same as above, but with responses
buffer.New(handler,
buffer.MemResponseBodyBytes(2 * 1024 * 1024),
buffer.MaxResponseBodyBytes(10 * 1024 * 1024))
// Buffer will replay the request if the handler returns error at least 3 times
// before returning the response
buffer.New(handler, buffer.Retry(`IsNetworkError() && Attempts() <= 2`))
*/
package buffer
@@ -93,7 +92,6 @@ func CondSetter(condition bool, setter optSetter) optSetter {
// Example of the predicate:
//
// `Attempts() <= 2 && ResponseCode() == 502`.
//
func Retry(predicate string) optSetter {
return func(b *Buffer) error {
p, err := parseExpression(predicate)
@@ -357,7 +355,7 @@ type bufferWriter struct {
// RFC2616 #4.4.
func (b *bufferWriter) expectBody(r *http.Request) bool {
if r.Method == "HEAD" {
if r.Method == http.MethodHead {
return false
}
if (b.code >= 100 && b.code < 200) || b.code == 204 || b.code == 304 {
+2 -3
View File
@@ -12,7 +12,7 @@
// After FallbackDuration time period passes, Circuit breaker enters "Recovering" state, during that state it will
// start passing some traffic back to the endpoints, increasing the amount of passed requests using linear function:
//
// allowedRequestsRatio = 0.5 * (Now() - StartRecovery())/RecoveryDuration
// allowedRequestsRatio = 0.5 * (Now() - StartRecovery())/RecoveryDuration
//
// Two scenarios are possible in the "Recovering" state:
// 1. Condition matches again, this will reset the state to "Tripped" and reset the timer.
@@ -22,7 +22,6 @@
//
// * OnTripped action is called on transition (Standby -> Tripped)
// * OnStandby action is called on transition (Recovering -> Standby)
//
package cbreaker
import (
@@ -239,7 +238,7 @@ func (c *CircuitBreaker) checkAndSet() {
defer c.m.Unlock()
// Other goroutine could have updated the lastCheck variable before we grabbed mutex
if !clock.Now().UTC().After(c.lastCheck) {
if clock.Now().UTC().Before(c.lastCheck) {
return
}
c.lastCheck = clock.Now().UTC().Add(c.checkPeriod)
+3 -4
View File
@@ -11,8 +11,7 @@ import (
// ratioController allows passing portions traffic back to the endpoints,
// increasing the amount of passed requests using linear function:
//
// allowedRequestsRatio = 0.5 * (Now() - Start())/Duration
//
// allowedRequestsRatio = 0.5 * (Now() - Start())/Duration
type ratioController struct {
duration time.Duration
start clock.Time
@@ -58,9 +57,9 @@ func (r *ratioController) computeRatio(allowed, denied int) float64 {
func (r *ratioController) targetRatio() float64 {
// Here's why it's 0.5:
// We are watching the following ratio
// We are watching the following ratio:
// ratio = a / (a + d)
// We can notice, that once we get to 0.5
// We can notice, that once we get to 0.5:
// 0.5 = a / (a + d)
// we can evaluate that a = d
// that means equilibrium, where we would allow all the requests
+1 -1
View File
@@ -123,7 +123,7 @@ func (e *ConnErrHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err
}
if _, ok := err.(*MaxConnError); ok {
w.WriteHeader(429)
w.WriteHeader(http.StatusTooManyRequests)
_, _ = w.Write([]byte(err.Error()))
return
}
+1 -1
View File
@@ -130,7 +130,7 @@ func (v *AESValue) fromValue(obfuscatedStr string) (string, error) {
if clock.Now().UTC().After(clock.Unix(i, 0).UTC()) {
strTime := clock.Unix(i, 0).UTC().String()
return "", fmt.Errorf("TTL expired: '%s' (%s)\n", raw, strTime)
return "", fmt.Errorf("TTL expired: '%s' (%s)", raw, strTime)
}
raw = []byte(rawParts[0])
+7 -8
View File
@@ -19,15 +19,14 @@ Risks:
Examples of a streaming middleware:
// sample HTTP handler
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
})
// Stream will literally pass through to the next handler without ANY buffering
// or validation of the data.
stream.New(handler)
// sample HTTP handler.
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("hello"))
})
// Stream will literally pass through to the next handler without ANY buffering
// or validation of the data.
stream.New(handler)
*/
package stream
+1 -1
View File
@@ -65,7 +65,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
reqBody = string(body)
contentLength = req.ContentLength
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
flusher, ok := w.(http.Flusher)
if !ok {
panic("expected http.ResponseWriter to be an http.Flusher")