From 9b20d3fe3afb60eccf94217af105a815762c67a5 Mon Sep 17 00:00:00 2001 From: Quentin Burgess Date: Thu, 11 May 2023 12:25:42 +0200 Subject: [PATCH] fix: realign struct --- .golangci.yml | 134 +++++++++++++----------------------------- options.go | 20 +++---- response_json_test.go | 28 ++++----- usecase_test.go | 4 +- 4 files changed, 68 insertions(+), 118 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7ddd9ca..99ee90e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,11 +10,10 @@ linters-settings: min-complexity: 15 gomoddirectives: # Allow local `replace` directives. - replace-local: true + replace-local: false # List of allowed `replace` directives. - replace-allow-list: - # - github.com/burgesQ/webfmwk/v5 - - frafos.com/json2redis + # replace-allow-list: + # - github.com/burgesQ/webfmwk/v5 gomnd: checks: argument,case,condition,operation,return,assign # ignored-numbers: '0o666','0o755' @@ -25,88 +24,23 @@ linters-settings: - shadow misspell: locale: US + maligned: + # print struct with more effective memory layout or not, false by default + suggest-new: true revive: ignore-generated-header: true severity: warning # enable-all-rules: true - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true - # # old settings - # depguard: - # list-type: blacklist - # packages: - # # logging is allowed only by gommon/golib/v4/log - # - github.com/sirupsen/logrus - # - log - # packages-with-error-message: - # - log: "logging is allowed only by golib/v4/log" - # - github.com/sirupsen/logrus: "logging is allowed only by golib/v4/log" - # dupl: - # threshold: 100 - # gci: - # local-prefixes: github.com/golangci/golangci-lint - # goconst: - # min-len: 2 - # min-occurrences: 2 - # gocritic: - # enabled-tags: - # - diagnostic - # - experimental - # - opinionated - # - performance - # - style - # # - ifElseChain - # # - octalLiteral - # # - wrapperFunc - # disabled-checks: - # - dupImport # https://github.com/go-critic/go-critic/issues/845 - # - whyNoLint - # - ioutilDeprecated - # # Conflicts with govet check-shadowing - # - sloppyReassign - # goimports: - # local-prefixes: github.com/golangci/golangci-lint - # # golint: - # # min-confidence: 0 - # # see https://github.com/mgechev/revive#available-rules for details. - # # govet: - # # check-shadowing: true - # # enable: - # # - fieldalignment - # # shadow: - # # strict: true - # # settings: - # # printf: - # # funcs: - # # - (gitlab.frafos.com/gommon/golib).Infof - # # - (gitlab.frafos.com/gommon/golib).Warnf - # # - (gitlab.frafos.com/gommon/golib).Errorf - # # - (gitlab.frafos.com/gommon/golib).Fatalf - # gomoddirectives: - # # Allow local `replace` directives. - # # Default: false - # replace-local: true - # # List of allowed `replace` directives. - # # Default: [] - # replace-allow-list: - # # - github.com/burgesQ/webfmwk/v5 - # - frafos.com/json2redis - # # Allow to not explain why the version has been retracted in the `retract` directives. - # # Default: false - # retract-allow-no-explanation: false - # # Forbid the use of the `exclude` directives. - # # Default: false - # exclude-forbidden: false - # lll: - # line-length: 140 - # maligned: - # suggest-new: true - # nolintlint: - # allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) - # allow-unused: false # report any unused nolint directives - # require-explanation: false # don't require an explanation for nolint directives - # require-specific: false # don't require nolint directives to be specific about which linter is being skipped + tagliatelle: + case: + rules: + json: snake + varnamelen: + ignore-decls: + - c context.Context + - c webfmwk.Context + - t testing.T + - e error linters: # please, do not use `enable-all`: it's deprecated and will be removed soon. @@ -114,24 +48,39 @@ linters: disable-all: true enable: - asasalint + - asciicheck - bidichk + - bodyclose + - containedctx + - contextcheck - cyclop - decorder - depguard - dogsled - dupl - dupword + - durationcheck - errcheck - errchkjson + - errname - errorlint - exhaustive + # - exhaustivestruct ## lazy - none is def + # - exhaustruct ## lazy - none is def + - exportloopref - forbidigo + # - forcetypeassert - funlen - gci + # - gocheckcompilerdirectives + - gochecknoinits - gocognit - goconst - gocritic + # - godox ## lazy - should uncomment + # - godot ## lazy - should uncomment - gocyclo + - goerr113 - gofmt - gofumpt - goheader @@ -140,13 +89,14 @@ linters: - gomoddirectives - gomodguard - gosimple + - goprintffuncname - gosec - govet - grouper - ifshort - importas - interfacebloat - # - ireturn + # - ireturn ## to uncomment .. - lll - loggercheck - maintidx @@ -154,8 +104,10 @@ linters: - misspell - nakedret - nestif + - nilerr - nilnil - nlreturn + - noctx - nolintlint - prealloc - predeclared @@ -165,29 +117,27 @@ linters: - rowserrcheck - staticcheck - stylecheck - # - tagliatelle ## should uncomment + - tagliatelle - tenv + - testableexamples - thelper + - unconvert - usestdlibvars - unparam + # - varnamelen ## to uncomment ... + - wastedassign - whitespace + # - wrapcheck ## to uncomment ... - wsl - - maligned ### don't enable: # - ginkgolinter ## don't work - # - exhaustivestruct ## lazy - none is def - # - exhaustruct ## lazy - none is def - # - godox ## lazy - should uncomment - # - godot ## lazy - should uncomment # - golint ## use revive # - maligned ## use fieldalignment # - nonamedreturns ## we name return on short func # - paralleltest # - testpackage ## we test internal stuff from pkg # - varcheck ## use unused - # - varnamelen ## lazy - let's live with it - # - wrapcheck ## lazy - to much work issues: @@ -203,7 +153,7 @@ issues: - forcetypeassert - gocritic - gosec - - govet + # - govet - noctx - wsl # - cyclop diff --git a/options.go b/options.go index 72023b1..559841c 100644 --- a/options.go +++ b/options.go @@ -34,23 +34,23 @@ type ( //nolint: govet serverMeta struct { - handlers []Handler // 24 - docHandlers []DocHandler // 24 + socketIOHandler http.Handler + socketIOHandlerFunc http.HandlerFunc baseServer *fasthttp.Server routes RoutesPerPrefix // 8 prefix string // 16 - ctrlc bool // 1 * 5 - checkIsUp bool - ctrlcStarted bool + pprofPath string + socketIOPath string + docHandlers []DocHandler // 24 + handlers []Handler // 24 cors bool - enableKeepAlive bool socketIOHF bool socketIOH bool pprof bool - socketIOHandlerFunc http.HandlerFunc - socketIOHandler http.Handler - socketIOPath string - pprofPath string + enableKeepAlive bool + ctrlcStarted bool + checkIsUp bool + ctrlc bool // 1 * 5 } ) diff --git a/response_json_test.go b/response_json_test.go index 9bd3284..82cf9d6 100644 --- a/response_json_test.go +++ b/response_json_test.go @@ -15,46 +15,46 @@ func TestJSONResponse(t *testing.T) { Message string `json:"message"` }{"nul"} tests = map[string]struct { - expectedOP int fn func(c Context, ret interface{}) error + expectedOP int }{ - "blob": {http.StatusOK, func(c Context, ret interface{}) error { + "blob": {expectedOP: http.StatusOK, fn: func(c Context, ret interface{}) error { return c.JSONBlob(http.StatusOK, []byte(hBody)) }}, - "ok": {http.StatusOK, func(c Context, ret interface{}) error { + "ok": {expectedOP: http.StatusOK, fn: func(c Context, ret interface{}) error { return c.JSONOk(ret) }}, - "created": {http.StatusCreated, func(c Context, ret interface{}) error { + "created": {expectedOP: http.StatusCreated, fn: func(c Context, ret interface{}) error { return c.JSONCreated(ret) }}, - "accepted": {http.StatusAccepted, func(c Context, ret interface{}) error { + "accepted": {expectedOP: http.StatusAccepted, fn: func(c Context, ret interface{}) error { return c.JSONAccepted(ret) }}, - "noContent": {http.StatusNoContent, func(c Context, ret interface{}) error { + "noContent": {expectedOP: http.StatusNoContent, fn: func(c Context, ret interface{}) error { return c.JSONNoContent() }}, - "badRequest": {http.StatusBadRequest, func(c Context, ret interface{}) error { + "badRequest": {expectedOP: http.StatusBadRequest, fn: func(c Context, ret interface{}) error { return c.JSONBadRequest(ret) }}, - "unauthorized": {http.StatusUnauthorized, func(c Context, ret interface{}) error { + "unauthorized": {expectedOP: http.StatusUnauthorized, fn: func(c Context, ret interface{}) error { return c.JSONUnauthorized(ret) }}, - "forbidden": {http.StatusForbidden, func(c Context, ret interface{}) error { + "forbidden": {expectedOP: http.StatusForbidden, fn: func(c Context, ret interface{}) error { return c.JSONForbidden(ret) }}, - "notFound": {http.StatusNotFound, func(c Context, ret interface{}) error { + "notFound": {expectedOP: http.StatusNotFound, fn: func(c Context, ret interface{}) error { return c.JSONNotFound(ret) }}, - "conflict": {http.StatusConflict, func(c Context, ret interface{}) error { + "conflict": {expectedOP: http.StatusConflict, fn: func(c Context, ret interface{}) error { return c.JSONConflict(ret) }}, - "unprocessable": {http.StatusUnprocessableEntity, func(c Context, ret interface{}) error { + "unprocessable": {expectedOP: http.StatusUnprocessableEntity, fn: func(c Context, ret interface{}) error { return c.JSONUnprocessable(ret) }}, - "internalError": {http.StatusInternalServerError, func(c Context, ret interface{}) error { + "internalError": {expectedOP: http.StatusInternalServerError, fn: func(c Context, ret interface{}) error { return c.JSONInternalError(ret) }}, - "notImplemented": {http.StatusNotImplemented, func(c Context, ret interface{}) error { + "notImplemented": {expectedOP: http.StatusNotImplemented, fn: func(c Context, ret interface{}) error { return c.JSONNotImplemented(ret) }}, } diff --git a/usecase_test.go b/usecase_test.go index 8844028..fb336f9 100644 --- a/usecase_test.go +++ b/usecase_test.go @@ -24,8 +24,8 @@ type userForm struct { } type queryParam struct { - Pretty bool `json:"pretty" schema:"pretty"` Some *int `json:"some,omitempty" schema:"some" validate:"omitempty,min=-1"` + Pretty bool `json:"pretty" schema:"pretty"` } //nolint:forcetypeassert @@ -182,7 +182,7 @@ func TestUseCase(t *testing.T) { }, "query to struct filled": { action: _reqNTest, url: "/api/test/queryToStruct?some=10&pretty", - body: "{\n \"pretty\": false,\n \"some\": 10\n}", code: http.StatusOK, + body: "{\n \"some\": 10,\n \"pretty\": false\n}", code: http.StatusOK, }, "query params pretty": {