Skip to content

Commit

Permalink
fix: realign struct
Browse files Browse the repository at this point in the history
  • Loading branch information
burgesQ committed May 11, 2023
1 parent 4e25cfd commit 9b20d3f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 118 deletions.
134 changes: 42 additions & 92 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -25,113 +24,63 @@ 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.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
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
Expand All @@ -140,22 +89,25 @@ linters:
- gomoddirectives
- gomodguard
- gosimple
- goprintffuncname
- gosec
- govet
- grouper
- ifshort
- importas
- interfacebloat
# - ireturn
# - ireturn ## to uncomment ..
- lll
- loggercheck
- maintidx
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- prealloc
- predeclared
Expand All @@ -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:
Expand All @@ -203,7 +153,7 @@ issues:
- forcetypeassert
- gocritic
- gosec
- govet
# - govet
- noctx
- wsl
# - cyclop
Expand Down
20 changes: 10 additions & 10 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand Down
28 changes: 14 additions & 14 deletions response_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}},
}
Expand Down
4 changes: 2 additions & 2 deletions usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 9b20d3f

Please sign in to comment.