fix lint
This commit is contained in:
1 parent
6bf8c4e6e3
commit
49ddbc5531
9 files changed
+30
-31
No files matched your search
@@ -15,6 +15,7 @@ linters:
|
||||
- nolintlint # Goland все равно форматирует с отступом
|
||||
- perfsprint # мнимая производительность в угоду читаемости
|
||||
- tagalign # не всегда имеет смысл
|
||||
- testpackage
|
||||
- varnamelen # очень индивидуально (db)
|
||||
- wsl # расставление пробелов очень индивидуально
|
||||
- wsl_v5 # расставление пробелов очень индивидуально
|
||||
@@ -65,6 +66,16 @@ linters:
|
||||
- unqueryvet
|
||||
- prealloc
|
||||
path: ".*_test\\.go$"
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: middleware #отсутствует необходимость оборачивать ошибки
|
||||
- linters:
|
||||
- gochecknoglobals
|
||||
- mnd
|
||||
path: proxy
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: httperrors #отсутствует необходимость оборачивать ошибки
|
||||
- linters:
|
||||
- goconst
|
||||
path: "tests/" # компонентные тесты: фикстуры и моки не выносим в константы
|
||||
|
||||
@@ -3,7 +3,6 @@ package httperrors
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/txix-open/isp-kit/errors"
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
@@ -34,11 +33,7 @@ func (e *HttpError) WriteError(w http.ResponseWriter) error {
|
||||
"errorMessage": e.userMessage,
|
||||
"details": e.details,
|
||||
}
|
||||
err := json.NewEncoder(w).Encode(data)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "json encode error")
|
||||
}
|
||||
return nil
|
||||
return json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
|
||||
func (e *HttpError) WithDetails(details ...any) {
|
||||
|
||||
@@ -35,11 +35,7 @@ func (w *writerWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
if !ok {
|
||||
return nil, nil, errors.New("writerWrapper: upstream writer doesn't implement Hijack")
|
||||
}
|
||||
conn, rw, err := upstream.Hijack()
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithMessage(err, "hijack error")
|
||||
}
|
||||
return conn, rw, nil
|
||||
return upstream.Hijack()
|
||||
}
|
||||
|
||||
func (w *writerWrapper) StatusCode() int {
|
||||
@@ -145,7 +141,7 @@ func Logger( // nolint:gocognit,funlen
|
||||
logger.Debug(ctx.Context(), "log request", fields...)
|
||||
}
|
||||
|
||||
return errors.WithMessage(err, "logger middleware error")
|
||||
return err
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"isp-gate-service/request"
|
||||
"time"
|
||||
|
||||
"isp-gate-service/request"
|
||||
|
||||
"github.com/txix-open/isp-kit/errors"
|
||||
"github.com/txix-open/isp-kit/metrics/http_metrics"
|
||||
)
|
||||
|
||||
@@ -22,7 +20,7 @@ func Metrics(storage *http_metrics.ServerStorage) Middleware {
|
||||
start := time.Now()
|
||||
err := next.Handle(ctx)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "metrics middleware error")
|
||||
return err
|
||||
}
|
||||
|
||||
storage.ObserveDuration(r.Method, pathSchema, time.Since(start))
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"isp-gate-service/request"
|
||||
)
|
||||
|
||||
@@ -16,10 +18,10 @@ func (f HandlerFunc) Handle(ctx *request.Context) error {
|
||||
|
||||
type Middleware func(next Handler) Handler
|
||||
|
||||
// nolint:ireturn, modernize
|
||||
//nolint:ireturn // Chain по определению возвращает Handler-интерфейс
|
||||
func Chain(root Handler, middlewares ...Middleware) Handler {
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
root = middlewares[i](root)
|
||||
for _, m := range slices.Backward(middlewares) {
|
||||
root = m(root)
|
||||
}
|
||||
return root
|
||||
}
|
||||
@@ -33,7 +33,6 @@ func init() {
|
||||
}
|
||||
|
||||
var (
|
||||
// nolint: gochecknoglobals
|
||||
codeMap = map[int]codes.Code{
|
||||
http.StatusOK: codes.OK,
|
||||
http.StatusRequestTimeout: codes.Canceled,
|
||||
@@ -49,7 +48,6 @@ var (
|
||||
http.StatusInternalServerError: codes.Internal,
|
||||
http.StatusServiceUnavailable: codes.Unavailable,
|
||||
}
|
||||
// nolint: gochecknoglobals
|
||||
inverseCodeMap = map[codes.Code]int{}
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// nolint: gochecknoglobals, mnd
|
||||
httpTransport = &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: defaultTransportDialContext(&net.Dialer{
|
||||
|
||||
@@ -46,7 +46,6 @@ func (ws Ws) Handle(ctx *request.Context) error {
|
||||
proxy.Director = func(incoming *http.Request, out http.Header) {
|
||||
setHttpHeaders(ctx, out, ws.skipAuth)
|
||||
}
|
||||
// nolint: mnd
|
||||
proxy.Upgrader = &websocket.Upgrader{
|
||||
HandshakeTimeout: 5 * time.Second,
|
||||
ReadBufferSize: 1024,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package tests_test
|
||||
// nolint:canonicalheader
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -238,7 +239,7 @@ type wsEventHandlerMock struct {
|
||||
|
||||
func (s wsEventHandlerMock) Handle(_ context.Context, conn *etp.Conn, event msg.Event) []byte {
|
||||
headers := conn.HttpRequest().Header
|
||||
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id")) // nolint: canonicalheader
|
||||
ctx := requestid.ToContext(context.Background(), headers.Get("x-request-id"))
|
||||
assertHeaders(s.require, s.requestId, ctx, headers)
|
||||
require.EqualValues(s.t, "data", event.Data)
|
||||
return []byte("world")
|
||||
@@ -630,13 +631,13 @@ func TestHappyPathTestSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func assertHeaders(require *require.Assertions, requestId string, ctx context.Context, headers http.Header) {
|
||||
systemId, err := strconv.Atoi(headers.Get("x-system-identity")) // nolint: canonicalheader
|
||||
systemId, err := strconv.Atoi(headers.Get("x-system-identity"))
|
||||
require.NoError(err)
|
||||
domainId, err := strconv.Atoi(headers.Get("x-domain-identity")) // nolint: canonicalheader
|
||||
domainId, err := strconv.Atoi(headers.Get("x-domain-identity"))
|
||||
require.NoError(err)
|
||||
serviceId, err := strconv.Atoi(headers.Get("x-service-identity")) // nolint: canonicalheader
|
||||
serviceId, err := strconv.Atoi(headers.Get("x-service-identity"))
|
||||
require.NoError(err)
|
||||
applicationId, err := strconv.Atoi(headers.Get("x-application-identity")) // nolint: canonicalheader
|
||||
applicationId, err := strconv.Atoi(headers.Get("x-application-identity"))
|
||||
require.NoError(err)
|
||||
require.EqualValues(requestId, requestid.FromContext(ctx))
|
||||
require.EqualValues(1, systemId)
|
||||
@@ -644,9 +645,9 @@ func assertHeaders(require *require.Assertions, requestId string, ctx context.Co
|
||||
require.EqualValues(3, serviceId)
|
||||
require.EqualValues(4, applicationId)
|
||||
expectedAppName := base64.StdEncoding.EncodeToString([]byte("test"))
|
||||
require.EqualValues(expectedAppName, headers.Get("x-application-name")) // nolint: canonicalheader
|
||||
require.EqualValues(expectedAppName, headers.Get("x-application-name"))
|
||||
|
||||
adminId, err := strconv.Atoi(headers.Get("x-admin-id")) // nolint: canonicalheader
|
||||
adminId, err := strconv.Atoi(headers.Get("x-admin-id"))
|
||||
require.NoError(err)
|
||||
require.EqualValues(1, adminId)
|
||||
}
|
||||
Reference in new issue
Block a user