diff --git a/.golangci.yml b/.golangci.yml index fc99f09..3ea672e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,38 +1,48 @@ -# This file contains all available configuration options -# Modified for linting cmd/ and pkg/ - -# options for analysis running +# Options for analysis running. run: - # default concurrency is a available CPU number + # The default concurrency value is the number of available CPU. # concurrency: 4 - # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 3m + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 5m - # exit code when at least one issue was found, default is 1 - issues-exit-code: 1 + # Exit code when at least one issue was found. + # Default: 1 + # issues-exit-code: 1 - # include test files or not, default is true - tests: true + # Include test files or not. + # Default: true + # tests: true - # list of build tags, all linters use it. Default is empty list. + # List of build tags, all linters use it. + # Default: []. # build-tags: + # - mytag - # which dirs to skip: they won't be analyzed; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but next dirs are always skipped independently - # from this option's value: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + # Which dirs to skip: issues from them won't be reported. + # Can use regexp here: `generated.*`, regexp is applied on full path. + # Default value is empty list, + # but default dirs are skipped independently of this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work on Windows. # skip-dirs: + # - src/external_libs + # - autogenerated_by_my_lib + # Enables skipping of directories: + # - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + # Default: true + skip-dirs-use-default: false - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. + # Which files to skip: they will be analyzed, but issues from them won't be reported. + # Default value is empty list, + # but there is no need to include all autogenerated files, + # we confidently recognize autogenerated files. + # If it's not please let us know. + # "/" will be replaced by current OS file path separator to properly work on Windows. skip-files: - "^mock_*\\.go$" - # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If set we pass it to "go list -mod={option}". From "go help modules": # If invoked with -mod=readonly, the go command is disallowed from the implicit # automatic updating of go.mod described above. Instead, it fails when any changes # to go.mod are needed. This setting is most useful to check that go.mod does @@ -40,223 +50,610 @@ run: # If invoked with -mod=vendor, the go command assumes that the vendor # directory holds the correct copies of dependencies and ignores # the dependency descriptions in go.mod. - modules-download-mode: mod + # + # Allowed values: readonly|vendor|mod + # By default, it isn't set. + modules-download-mode: readonly + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: false + + # Define the Go version limit. + # Mainly related to generics support since go1.18. + # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18 + # go: '1.19' # output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number" + # Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity + # + # Multiple can be specified by separating them by comma, output can be provided + # for each of them by separating format name and path by colon symbol. + # Output path can be either `stdout`, `stderr` or path to the file to write to. + # Example: "checkstyle:report.xml,json:stdout,colored-line-number" + # + # Default: colored-line-number format: colored-line-number - # print lines of code with issue, default is true + # Print lines of code with issue. + # Default: true print-issued-lines: true - # print linter name in the end of issue text, default is true + # Print linter name in the end of issue text. + # Default: true print-linter-name: true -# all available settings of specific linters -linters-settings: - staticcheck: - # Select the Go version to target. The default is '1.13'. - go: "1.19" - # https://staticcheck.io/docs/options#checks - checks: ["all"] + # Make issues output unique by line. + # Default: true + # uniq-by-line: false - errcheck: - # report about not checking of errors in type assertions: `a := b.(MyStruct)`; - # default is false: such cases aren't reported by default. - check-type-assertions: false + # Add a prefix to the output file references. + # Default is no prefix. + # path-prefix: "" - # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; - # default is false: such cases aren't reported by default. - check-blank: true - govet: - # report about shadowed variables - check-shadowing: true - - # Obtain type information from installed (to $GOPATH/pkg) package files: - # golangci-lint will execute `go install -i` and `go test -i` for analyzed packages - # before analyzing them. - # By default this option is disabled and govet gets type information by loader from source code. - # Loading from source code is slow, but it's done only once for all linters. - # Go-installing of packages first time is much slower than loading them from source code, - # therefore this option is disabled by default. - # But repeated installation is fast in go >= 1.10 because of build caching. - # Enable this option only if all conditions are met: - # 1. you use only "fast" linters (--fast e.g.): no program loading occurs - # 2. you use go >= 1.10 - # 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI. - use-installed-packages: false - revive: - # Sets the default failure confidence. - # This means that linting errors with less than 0.8 confidence will be ignored. - # Default: 0.8 - confidence: 0.8 - gofmt: - # simplify code: gofmt with `-s` option, true by default - simplify: true - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 10 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true - dupl: - # tokens count to trigger issue, 150 by default - threshold: 100 - goconst: - # minimal length of string constant, 3 by default - min-len: 3 - # minimal occurrences count to trigger, 3 by default - min-occurrences: 3 - depguard: - list-type: blacklist - include-go-root: false - packages: - - github.com/pkg/errors - misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. - locale: US - lll: - # max line length, lines longer will be reported. Default is 120. - # '\t' is counted as 1 character by default, and can be changed with the tab-width option - line-length: 120 - # tab width in spaces. Default to 1. - tab-width: 1 - unused: - # treat code as a program (not a library) and report unused exported identifiers; default is false. - # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find funcs usages. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - unparam: - # call graph construction algorithm (cha, rta). In general, use cha for libraries, - # and rta for programs with main packages. Default is cha. - algo: cha - - # Inspect exported functions, default is false. Set to true if no external program/library imports your code. - # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find external interfaces. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - nakedret: - # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 - max-func-lines: 30 - prealloc: - # XXX: we don't recommend using this linter before doing performance profiling. - # For most programs usage of prealloc will be a premature optimization. - - # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. - # True by default. - simple: true - range-loops: true # Report preallocation suggestions on range loops, true by default - for-loops: false # Report preallocation suggestions on for loops, false by default - goimports: - local-prefixes: github.com/spacemeshos/go-scale - gci: - sections: - - standard - - default - - prefix(github.com/spacemeshos/go-scale) - godot: - # comments to be checked: `declarations`, `toplevel`, or `all` - scope: declarations - # list of regexps for excluding particular comment lines from check - exclude: [] - # example: exclude comments which contain numbers - # - '[0-9]+' - # check that each sentence starts with a capital letter - capital: false - gofumpt: - # Select the Go version to target. The default is `1.15`. - lang-version: "1.19" - # Choose whether or not to use the extra rules that are disabled - # by default - extra-rules: false - whitespace: - multi-if: false # Enforces newlines (or comments) after every multi-line if statement - multi-func: false # Enforces newlines (or comments) after every multi-line function signature - wrapcheck: - # An array of strings that specify substrings of signatures to ignore. - # If this set, it will override the default set of ignored signatures. - # See https://github.com/tomarrell/wrapcheck#configuration for more information. - ignoreSigs: - # Default sigs - - .Errorf( - - errors.New( - - errors.Unwrap( - - .Wrap( - - .Wrapf( - - .WithMessage( - - .WithMessagef( - - .WithStack( - # Custom sigs - - .Error( - - .Err( - ignorePackageGlobs: - - encoding/* - - github.com/pkg/* + # Sort results by: filepath, line and column. + # sort-results: false linters: - # TODO(nkryuchkov): enable needed linters + # Disable all linters. + # Default: false + disable-all: true + + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default enable: + # - asasalint + # - asciicheck + # - bidichk + # - bodyclose + # - containedctx + # - contextcheck + # - cyclop + # - deadcode + # - decorder + - depguard + # - dogsled + # - dupl + # - dupword + # - durationcheck + # - errcheck + # - errchkjson + # - errname + # - errorlint + # - execinquery + # - exhaustive + # - exhaustivestruct + # - exhaustruct + # - exportloopref + # - forbidigo + # - forcetypeassert + # - funlen - gci + # - ginkgolinter + # - gocheckcompilerdirectives + # - gochecknoglobals + # - gochecknoinits + # - gocognit + # - goconst + # - gocritic + # - gocyclo - godot + # - godox + # - goerr113 - gofmt - gofumpt - - revive + # - goheader + # - goimports + # - golint + # - gomnd + # - gomoddirectives + # - gomodguard + # - goprintffuncname + # - gosec + - gosimple + # - gosmopolitan + - govet + # - grouper + # - ifshort + - importas + - ineffassign + # - interfacebloat + # - interfacer + # - ireturn + # - lll + # - loggercheck + # - maintidx + # - makezero + # - maligned + # - mirror - misspell + # - musttag + - nakedret + # - nestif + # - nilerr + # - nilnil + # - nlreturn + # - noctx + # - nolintlint + # - nonamedreturns + # - nosnakecase + # - nosprintfhostport + # - paralleltest + # - prealloc + # - predeclared + # - promlinter + # - reassign + - revive + # - rowserrcheck + # - scopelint + # - sqlclosecheck - staticcheck - - whitespace - # - wrapcheck - # - varcheck - # - unparam - # - deadcode # - structcheck - # - errcheck - # - gosimple - # - unused - # - ineffassign - # - typecheck - # - gosec - # - megacheck - # - nakedret - # - depguard + # - stylecheck + # - tagalign + # - tagliatelle + # - tenv + # - testableexamples + # - testpackage + # - thelper + # - tparallel + - typecheck + # - unconvert + # - unparam + - unused + # - usestdlibvars + # - varcheck + # - varnamelen + # - wastedassign + # - whitespace + # - wrapcheck + # - wsl + # - zerologlint + + # Enable all available linters. + # Default: false enable-all: false + + # Disable specific linter + # https://golangci-lint.run/usage/linters/#disabled-by-default # disable: - disable-all: true + # - asasalint + # - asciicheck + # - bidichk + # - bodyclose + # - containedctx + # - contextcheck + # - cyclop + # - deadcode + # - decorder + # - depguard + # - dogsled + # - dupl + # - dupword + # - durationcheck + # - errcheck + # - errchkjson + # - errname + # - errorlint + # - execinquery + # - exhaustive + # - exhaustivestruct + # - exhaustruct + # - exportloopref + # - forbidigo + # - forcetypeassert + # - funlen + # - gci + # - ginkgolinter + # - gocheckcompilerdirectives + # - gochecknoglobals + # - gochecknoinits + # - gocognit + # - goconst + # - gocritic + # - gocyclo + # - godot + # - godox + # - goerr113 + # - gofmt + # - gofumpt + # - goheader + # - goimports + # - golint + # - gomnd + # - gomoddirectives + # - gomodguard + # - goprintffuncname + # - gosec + # - gosimple + # - gosmopolitan + # - govet + # - grouper + # - ifshort + # - importas + # - ineffassign + # - interfacebloat + # - interfacer + # - ireturn + # - lll + # - loggercheck + # - maintidx + # - makezero + # - maligned + # - mirror + # - misspell + # - musttag + # - nakedret + # - nestif + # - nilerr + # - nilnil + # - nlreturn + # - noctx + # - nolintlint + # - nonamedreturns + # - nosnakecase + # - nosprintfhostport + # - paralleltest + # - prealloc + # - predeclared + # - promlinter + # - reassign + # - revive + # - rowserrcheck + # - scopelint + # - sqlclosecheck + # - staticcheck + # - structcheck + # - stylecheck + # - tagalign + # - tagliatelle + # - tenv + # - testableexamples + # - testpackage + # - thelper + # - tparallel + # - typecheck + # - unconvert + # - unparam + # - unused + # - usestdlibvars + # - varcheck + # - varnamelen + # - wastedassign + # - whitespace + # - wrapcheck + # - wsl + # - zerologlint + + # Enable presets. + # https://golangci-lint.run/usage/linters # presets: + # - bugs + # - comment + # - complexity + # - error + # - format + # - import + # - metalinter + # - module + # - performance + # - sql + # - style + # - test + # - unused + + # Run only fast linters from enabled linters set (first run won't be fast) + # Default: false fast: false +# All available settings of specific linters. +linters-settings: + depguard: + # Rules to apply. + # + # Variables: + # - File Variables + # you can still use and exclamation mark ! in front of a variable to say not to use it. + # Example !$test will match any file that is not a go test file. + # + # `$all` - matches all go files + # `$test` - matches all go test files + # + # - Package Variables + # + # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) + # + # Default: Only allow $gostd in all files. + rules: + # Name of a rule. + main: + # List of file globs that will match this list of settings to compare against. + # Default: $all + # files: + # - "!**/*_a _file.go" + # List of allowed packages. + # allow: + # - $gostd + # - github.com/OpenPeeDeeP + # Packages that are not allowed where the value is a suggestion. + deny: + - pkg: "io/ioutil" + desc: Use os instead + - pkg: "github.com/pkg/errors" + desc: Should be replaced by standard lib errors package + - pkg: "golang.org/x/xerrors" + desc: Should be replaced by standard lib errors package + - pkg: "golang.org/x/net/context" + desc: Should be replaced by standard lib context package + - pkg: "golang.org/x/crypto/ed25519" + desc: Should be replaced by standard lib ed25519 package + + gci: + # Section configuration to compare against. + # Section names are case-insensitive and may contain parameters in (). + # The default order of sections is `standard > default > custom > blank > dot`, + # If `custom-order` is `true`, it follows the order of `sections` option. + # Default: ["standard", "default"] + sections: + - standard + - default + - prefix(github.com/spacemeshos/go-scale) + + # Skip generated files. + # Default: true + # skip-generated: false + + # Enable custom order of sections. + # If `true`, make the section order the same as the order of `sections`. + # Default: false + # custom-order: true + + goconst: + # Minimal length of string constant. + # Default: 3 + # min-len: 3 + + # Minimum occurrences of constant string count to trigger issue. + # Default: 3 + # min-occurrences: 3 + + # Ignore test files. + # Default: false + # ignore-tests: false + + # Look for existing constants matching the values. + # Default: true + # match-constant: true + + # Search also for duplicated numbers. + # Default: false + # numbers: false + + # Minimum value, only works with goconst.numbers + # Default: 3 + # min: 3 + + # Maximum value, only works with goconst.numbers + # Default: 3 + # max: 3 + + # Ignore when constant is not used as function argument. + # Default: true + ignore-calls: false + + godot: + # Comments to be checked: `declarations`, `toplevel`, or `all`. + # Default: declarations + # scope: declarations + + # List of regexps for excluding particular comment lines from check. + # Default: [] + exclude: + # Exclude todo and fixme comments. + - "^FIXME:" + - "^TODO:" + + # Check that each sentence ends with a period. + # Default: true + # period: true + + # Check that each sentence starts with a capital letter. + # Default: false + # capital: false + + gofmt: + # Simplify code: gofmt with `-s` option. + # Default: true + #simplify: true + + # Apply the rewrite rules to the source before reformatting. + # https://pkg.go.dev/cmd/gofmt + # Default: [] + rewrite-rules: + - pattern: "interface{}" + replacement: "any" + - pattern: "a[b:len(a)]" + replacement: "a[b:]" + + gofumpt: + # Module path which contains the source code being formatted. + # Default: "" + # module-path: github.com/org/project + + # Choose whether to use the extra rules. + # Default: false + extra-rules: true + + gosimple: + # Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks + # Default: ["*"] + checks: ["all"] + + govet: + # Report about shadowed variables. + # Default: false + check-shadowing: false + # Disable all analyzers. + # Default: false + disable-all: false + # Enable analyzers by name (in addition to default). + # Run `go tool vet help` to see all analyzers. + # Default: [] + # enable: + # Enable all analyzers. + # Default: false + enable-all: false + # Disable analyzers by name. + # Run `go tool vet help` to see all analyzers. + # Default: [] + # disable: + + importas: + # Do not allow unaliased imports of aliased packages. + # Default: false + # no-unaliased: false + + # Do not allow non-required aliases. + # Default: false + # no-extra-aliases: false + + # List of aliases + # Default: [] + alias: + - pkg: "github.com/chaos-mesh/chaos-mesh/api/v1alpha1" + alias: chaos + - pkg: "github.com/hashicorp/golang-lru/v2" + alias: lru + - pkg: "github.com/grpc-ecosystem/go-grpc-middleware" + alias: grpcmw + - pkg: "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" + alias: grpczap + - pkg: "github.com/grpc-ecosystem/go-grpc-middleware/tags" + alias: grpctags + - pkg: "github.com/libp2p/go-libp2p-pubsub" + alias: pubsub + - pkg: "github.com/libp2p/go-libp2p-pubsub/pb" + alias: pubsubpb + - pkg: "github.com/libp2p/go-libp2p/p2p/net/mock" + alias: mocknet + - pkg: "github.com/libp2p/go-libp2p-testing/netutil" + alias: p2putil + - pkg: "github.com/multiformats/go-multiaddr" + alias: ma + - pkg: "github.com/multiformats/go-multiaddr/net" + alias: manet + - pkg: "github.com/spacemeshos/api/release/go/spacemesh/v1" + alias: pb + - pkg: "github.com/spacemeshos/go-spacemesh/genvm" + alias: vm + - pkg: "github.com/spacemeshos/go-spacemesh/p2p/metrics" + alias: p2pmetrics + - pkg: "github.com/spacemeshos/go-spacemesh/sql/proposals" + alias: dbproposals + - pkg: "github.com/spacemeshos/go-spacemesh/sql/metrics" + alias: dbmetrics + - pkg: "github.com/spacemeshos/go-spacemesh/txs/types" + alias: txtypes + - pkg: "google.golang.org/genproto/googleapis/rpc/status" + alias: rpcstatus + - pkg: "k8s.io/apimachinery/pkg/apis/meta/v1" + alias: apimetav1 + - pkg: "k8s.io/api/apps/v1" + alias: apiappsv1 + - pkg: "k8s.io/api/core/v1" + alias: apiv1 + - pkg: "k8s.io/client-go/applyconfigurations/apps/v1" + alias: appsv1 + - pkg: "k8s.io/client-go/applyconfigurations/core/v1" + alias: corev1 + - pkg: "k8s.io/client-go/applyconfigurations/meta/v1" + alias: metav1 + + misspell: + # Correct spellings using locale preferences for US or UK. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + # Default is to use a neutral variety of English. + locale: US + + nakedret: + # Make an issue if func has more lines of code than this setting, and it has naked returns. + # Default: 30 + max-func-lines: 30 + + revive: + # Sets the default failure confidence. + # This means that linting errors with less than 0.8 confidence will be ignored. + # Default: 0.8 + confidence: 0.8 + + staticcheck: + # SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks + # Default: ["*"] + checks: ["all", "-SA5001"] + issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` + # List of regexps of issue texts to exclude. + # + # But independently of this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. + # To list all excluded by default patterns execute `golangci-lint run --help` + # + # Default: https://golangci-lint.run/usage/false-positives/#default-exclusions # exclude: - + # - abcdef + # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: + # Exclude some `staticcheck` messages. - linters: - staticcheck - text: SA1019 - - # Independently from option `exclude` we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute `golangci-lint run --help`. - # Default value for this option is true. + text: "SA1019:" + # Independently of option `exclude` we use default exclude patterns, + # it can be disabled by this option. + # To list all excluded by default patterns execute `golangci-lint run --help`. + # Default: true. exclude-use-default: false - - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - max-per-linter: 0 - - # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. - max-same: 0 - + # If set to true exclude and exclude-rules regular expressions become case-sensitive. + # Default: false + exclude-case-sensitive: false + # The list of ids of default excludes to include or disable. + # https://golangci-lint.run/usage/false-positives/#default-exclusions + # Default: [] + # include: + # - EXC0001 + # - EXC0002 + # - EXC0003 + # - EXC0004 + # - EXC0005 + # - EXC0006 + # - EXC0007 + # - EXC0008 + # - EXC0009 + # - EXC0010 + # - EXC0011 + # - EXC0012 + # - EXC0013 + # - EXC0014 + # - EXC0015 + # Maximum issues count per one linter. + # Set to 0 to disable. + # Default: 50 + max-issues-per-linter: 0 + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 0 # Show only new issues: if there are unstaged changes or untracked files, # only those changes are analyzed, else only changes in HEAD~ are analyzed. - # It's a super-useful option for integration of golangci-lint into existing - # large codebase. It's not practical to fix all existing issues at the moment - # of integration: much better don't allow issues in new code. - # Default is false. - new: false + # It's a super-useful option for integration of golangci-lint into existing large codebase. + # It's not practical to fix all existing issues at the moment of integration: + # much better don't allow issues in new code. + # + # Default: false. + # new: true + # Show only new issues created after git revision `REV`. + # new-from-rev: HEAD + # Show only new issues created in git patch with set file path. + # new-from-patch: path/to/patch/file + # Fix found issues (if it's supported by the linter). + # fix: true diff --git a/Makefile b/Makefile index 306adb8..e1b1bd9 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,9 @@ test: install: go mod download - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.0 - go install gotest.tools/gotestsum@v1.8.2 - go install honnef.co/go/tools/cmd/staticcheck@latest + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.53.3 + go install gotest.tools/gotestsum@v1.10.0 + go install honnef.co/go/tools/cmd/staticcheck@v0.4.3 .PHONY: install tidy: diff --git a/encoder.go b/encoder.go index d005601..8c5ab5c 100644 --- a/encoder.go +++ b/encoder.go @@ -278,7 +278,7 @@ func EncodeCompact64(e *Encoder, v uint64) (int, error) { return encodeBigUint(e, uint64(v)) } -func EncodeLen(e *Encoder, v uint32, limit uint32) (int, error) { +func EncodeLen(e *Encoder, v, limit uint32) (int, error) { if v > limit { return 0, fmt.Errorf("%w: %d", ErrEncodeTooManyElements, limit) } diff --git a/generate.go b/generate.go index 8f3ce51..37b0c6b 100644 --- a/generate.go +++ b/generate.go @@ -130,7 +130,7 @@ func getAction(tm temp, action int) string { panic("unreachable") } -func Generate(pkg string, filepath string, objs ...interface{}) error { +func Generate(pkg, filepath string, objs ...any) error { buf := bytes.NewBuffer(nil) ctx := &genContext{Package: pkg, Imported: generateImports(objs...)} @@ -155,7 +155,7 @@ func Generate(pkg string, filepath string, objs ...interface{}) error { return os.WriteFile(filepath, data, 0o664) } -func generateImports(objs ...interface{}) map[string]struct{} { +func generateImports(objs ...any) map[string]struct{} { rst := map[string]struct{}{} for _, obj := range objs { typ := reflect.TypeOf(obj) @@ -228,7 +228,7 @@ func builtin(typ reflect.Type) bool { return typ.PkgPath() == "" } -func generateType(w io.Writer, gc *genContext, obj interface{}) error { +func generateType(w io.Writer, gc *genContext, obj any) error { typ := reflect.TypeOf(obj) tc := &typeContext{ Name: typ.Name(),