From 1e7e260cb2af2031fc519faada7272e9a8fe189b Mon Sep 17 00:00:00 2001 From: Alonza0314 Date: Thu, 17 Jul 2025 08:03:38 +0000 Subject: [PATCH 1/5] chore: upgrade go 1.24 --- .github/workflows/go.yml | 2 +- .github/workflows/golangci-lint.yml | 6 +- .golangci.yml | 470 +++++++-------------------- go.mod | 27 +- go.sum | 49 ++- internal/gmm/handler.go | 2 +- internal/sbi/consumer/nrf_service.go | 2 +- 7 files changed, 160 insertions(+), 398 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index bfa5da0a..f0b0a6b9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: ['1.21' ] + go: ['1.24' ] name: Go ${{ matrix.go }} sample steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 0e0fed85..a07942e3 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.21' ] + go: [ '1.24' ] steps: - name: Set up Go uses: actions/setup-go@v5 @@ -21,10 +21,10 @@ jobs: go-version: ${{ matrix.go }} - uses: actions/checkout@v4 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v8 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.57.2 + version: v2.1.6 # Optional: working directory, useful for monorepos # working-directory: somedir diff --git a/.golangci.yml b/.golangci.yml index 02663f30..5d66091f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,381 +1,145 @@ - -# options for analysis running +version: "2" run: - # Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously. - # If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota. - # Default: the number of logical CPUs in the machine concurrency: 4 - - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 3m - - # exit code when at least one issue was found, default is 1 + go: "1.21" issues-exit-code: 1 - - # include test files or not, default is true tests: true - - # list of build tags, all linters use it. Default is empty list. - build-tags: [] - - # 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 - # not need updates, such as in a continuous integration and testing system. - # 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. - # - # Allowed values: readonly|vendor|mod - # Default: "" - # modules-download-mode: readonly - - # Allow multiple parallel golangci-lint instances running. - # If false, golangci-lint acquires file lock on start. - # Default: false allow-parallel-runners: true - - # Allow multiple golangci-lint instances running, but serialize them around a lock. - # If false, golangci-lint exits with an error if it fails to acquire file lock on start. - # Default: false allow-serial-runners: true - - go: '1.21' - -# output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - formats: - - format: "colored-line-number" + formats: + text: path: stdout - - # print lines of code with issue, default is true - print-issued-lines: true - # print linter name in the end of issue text, default is true - print-linter-name: true - # make issues output unique by line, default is true - uniq-by-line: true - - # Sort results by the order defined in `sort-order`. - # Default: false - sort-results: true + print-linter-name: true + print-issued-lines: true sort-order: - linter - severity - - file # filepath, line, and column. - show-stats: true - -# all available settings of specific linters -linters-settings: - 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 - # 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 - # [deprecated] comma-separated list of pairs of the form pkg:regex - # the regex is used to ignore names within pkg. (default "fmt:.*"). - # see https://github.com/kisielk/errcheck#the-deprecated-method for details - #ignore: fmt:.*,io/ioutil:^Read.* - # path to a file containing a list of functions to exclude from checking - # see https://github.com/kisielk/errcheck#excluding-functions for details - #exclude: /path/to/file.txt - - goconst: - # minimal length of string constant, 3 by default - min-len: 5 - # Minimum occurrences of constant string count to trigger issue, 3 by default - min-occurrences: 3 - # Exclude strings matching the given regular expression. - # Default: "" - ignore-strings: "get|post|put|delete|patch|options|head" - - gocritic: - # Which checks should be enabled; can't be combined with 'disabled-checks'; - # See https://go-critic.github.io/overview#checks-overview - # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` - # By default list of stable checks is used. - enabled-checks: [] - #- rangeValCopy - # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty - disabled-checks: - - regexpMust - # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. - # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". - enabled-tags: - - diagnostic - - performance - disabled-tags: - - experimental - - # settings passed to gocritic - # The settings key is the name of a supported gocritic checker. - # The list of supported checkers can be find in https://go-critic.github.io/overview. - settings: - captLocal: # must be valid enabled check name - # Whether to restrict checker to params only. - paramsOnly: true - rangeValCopy: - # Size in bytes that makes the warning trigger. Default: 128 - # This size shoulb be smaller - sizeThreshold: 512 - hugeParam: - # Size in bytes that makes the warning trigger. Default: 80 - # This size shoulb be smaller - sizeThreshold: 512 - ifElseChain: - # Min number of if-else blocks that makes the warning trigger. - # Default: 2 - minThreshold: 4 - - godox: - # report any comments starting with keywords, this is useful for TODO or FIXME comments that - # might be left in the code accidentally and should be resolved before merging - keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting - #- TODO - - FIXME - - BUG - #- NOTE - #- OPTIMIZE # marks code that should be optimized before merging - #- HACK # marks hack-arounds that should be removed before merging - - XXX # Fatal! Important problem - - gofmt: - # simplify code: gofmt with `-s` option, true by default - simplify: true - - govet: - enable-all: false - # enable or disable analyzers by name - enable: - - atomicalign - - shadow - - printf - - # settings per analyzer - settings: - # analyzer name, run `go tool vet help` to see all analyzers - printf: - funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - shadow: - # Whether to be strict about shadowing; can be noisy. - # Default: false - strict: true - - depguard: - rules: - # Name of a rule. - main: - # Used to determine the package matching priority. - # There are three different modes: `original`, `strict`, and `lax`. - # Default: "original" - list-mode: original - deny: - - pkg: github.com/sirupsen/logrus - desc: "logging is allowed only by logutils.Log" - - 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 - - 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 - - testpackage: - # regexp pattern to skip files - skip-regexp: (export|internal)_test\.go - - unused: - # Mark all struct fields that have been written to as used. - # Default: true - field-writes-are-uses: true - # Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write. - # Default: false - post-statements-are-reads: true - # Mark all exported identifiers as used. - # Default: true - exported-is-used: true - # Mark all exported fields as used. - # default: true - exported-fields-are-used: true - # Mark all function parameters as used. - # default: true - parameters-are-used: true - # Mark all local variables as used. - # default: true - local-variables-are-used: true - # Mark all identifiers inside generated files as used. - # Default: true - generated-is-used: true - - 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 - - gci: - sections: - - standard - - default - - prefix(github.com/free5gc) - - # Skip generated files. - # Default: true - skip-generated: true - - # Enable custom order of sections. - # If `true`, make the section order the same as the order of `sections`. - # Default: false - custom-order: true - - misspell: - locale: US - ignore-words: [] - - gomnd: - # !important in golangci-lint v1.58.0, gomnd is replaced by mnd - # List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. - # Default: ["argument", "case", "condition", "operation", "return", "assign"] - checks: - # - argument - - case - # - condition - - operation - - return - # - assign - # List of numbers to exclude from analysis. - # The numbers should be written as string. - # Values always ignored: "1", "1.0", "0" and "0.0" - # Default: [] - ignored-numbers: [] - # List of file patterns to exclude from analysis. - # Values always ignored: `.+_test.go` - # Default: [] - ignored-files: [] - # List of function patterns to exclude from analysis. - # Following functions are always ignored: `time.Date`, - # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, - # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`. - # Default: [] - ignored-functions: - - 'os\.Mkdir' - - 'os\.MkdirAll' - - '^math\.' - - '^http\.StatusText$' - - # custom: - # Each custom linter should have a unique name. - + - file linters: - disable-all: true + default: none enable: + - asciicheck + - bodyclose + - dogsled - errcheck - goconst - gocritic - godox - - gofmt - govet + - ineffassign - lll + - misspell - nakedret - # - testpackage + - noctx + - predeclared - staticcheck + - unconvert - unused - whitespace - - gci - - misspell - - gosimple - # - gomnd - - ineffassign - - typecheck - - gofumpt - - unconvert - - predeclared - - noctx - - dogsled - - bodyclose - - asciicheck - # - dupl - - # Enable only fast linters from enabled linters set (first run won't be fast) - # Default: false - fast: true - - + settings: + depguard: + rules: + main: + list-mode: original + deny: + - pkg: github.com/sirupsen/logrus + desc: logging is allowed only by logutils.Log + errcheck: + check-type-assertions: false + check-blank: true + goconst: + min-len: 5 + min-occurrences: 3 + ignore-strings: get|post|put|delete|patch|options|head + gocritic: + disabled-checks: + - regexpMust + enabled-tags: + - diagnostic + - performance + disabled-tags: + - experimental + settings: + captLocal: + paramsOnly: true + hugeParam: + sizeThreshold: 512 + ifElseChain: + minThreshold: 4 + rangeValCopy: + sizeThreshold: 512 + godox: + keywords: + - FIXME + - BUG + - XXX + govet: + enable: + - atomicalign + - shadow + - printf + enable-all: false + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + shadow: + strict: true + lll: + line-length: 120 + tab-width: 1 + misspell: + locale: US + nakedret: + max-func-lines: 30 + testpackage: + skip-regexp: (export|internal)_test\.go + unused: + field-writes-are-uses: true + post-statements-are-reads: true + exported-fields-are-used: true + parameters-are-used: true + local-variables-are-used: true + generated-is-used: true + whitespace: + multi-if: false + multi-func: false + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ 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` - exclude: [] - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: [] - # Exclude some linters from running on tests files. - # 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. - exclude-use-default: false - # The default value is false. If set to true exclude and exclude-rules - # regular expressions become case sensitive. - exclude-case-sensitive: false - # The list of ids of default excludes to include or disable. By default it's empty. - include: [] - #- EXC0002 # disable excluding of issues about comments from golint - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - #max-issues-per-linter: 0 - # Maximum count of issues with the same text. Set to 0 to disable. Default is 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 - # Show only new issues created after git revision `REV` new-from-rev: "" - # Show only new issues created in git patch with set file path. - #new-from-patch: path/to/patch/file - + new: false severity: - # Set the default severity for issues. - # - # If severity rules are defined and the issues do not match or no severity is provided to the rule - # this will be the default severity applied. - # Severities should match the supported severity names of the selected out format. - # - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity - # - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#SeverityLevel - # - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message - # - TeamCity: https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance - # - # `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...) - # - # Default: "" - default-severity: error - - # The default value is false. - # If set to true severity-rules regular expressions become case sensitive. - case-sensitive: false - - # When a list of severity rules are provided, severity information will be added to lint issues. - # Severity rules have the same filtering capability as exclude rules - # except you are allowed to specify one matcher per severity rule. - # - # `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...) - # - # Only affects out formats that support setting severity information. - # - # Default: [] + default: error rules: - linters: - - gomnd - severity: info \ No newline at end of file + - mnd + severity: info +formatters: + enable: + - gci + - gofmt + - gofumpt + settings: + gci: + sections: + - standard + - default + - prefix(github.com/free5gc) + custom-order: true + gofmt: + simplify: true + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/go.mod b/go.mod index 6c6ac34c..3c90c0f2 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,17 @@ module github.com/free5gc/amf -go 1.21 -toolchain go1.24.1 +go 1.24 require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 github.com/davecgh/go-spew v1.1.1 github.com/free5gc/aper v1.0.6-0.20250102035630-3ddc831eed6a - github.com/free5gc/nas v1.1.5 - github.com/free5gc/ngap v1.0.10 - github.com/free5gc/openapi v1.1.0 - github.com/free5gc/sctp v1.0.1 - github.com/free5gc/util v1.0.6 - github.com/gin-gonic/gin v1.9.1 + github.com/free5gc/nas v1.2.0 + github.com/free5gc/ngap v1.1.0 + github.com/free5gc/openapi v1.2.0 + github.com/free5gc/sctp v1.1.0 + github.com/free5gc/util v1.1.0 + github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/mitchellh/mapstructure v1.5.0 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 @@ -27,9 +26,9 @@ require ( require ( github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 // indirect - github.com/bytedance/sonic v1.11.5 // indirect + github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect - github.com/cloudwego/base64x v0.1.3 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -39,7 +38,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.19.0 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.2 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect @@ -53,7 +52,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.2.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -67,13 +66,13 @@ require ( go.opentelemetry.io/otel v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.24.0 // indirect - golang.org/x/arch v0.7.0 // indirect + golang.org/x/arch v0.8.0 // indirect golang.org/x/crypto v0.36.0 // indirect golang.org/x/net v0.38.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 27e3cd24..a34fefb3 100644 --- a/go.sum +++ b/go.sum @@ -2,13 +2,12 @@ github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 h1:+JkXLHME8vLJafGhOH4ao github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1/go.mod h1:nuudZmJhzWtx2212z+pkuy7B6nkBqa+xwNXZHL1j8cg= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/bytedance/sonic v1.11.5 h1:G00FYjjqll5iQ1PYXynbg/hyzqBqavH8Mo9/oTopd9k= -github.com/bytedance/sonic v1.11.5/go.mod h1:X2PC2giUdj/Cv2lliWFLk6c/DUQok5rViJSemeB0wDw= -github.com/bytedance/sonic/loader v0.1.0/go.mod h1:UmRT+IRTGKz/DAkzcEGzyVqQFJ7H9BqwBO3pm9H/+HY= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/cloudwego/base64x v0.1.3 h1:b5J/l8xolB7dyDTTmhJP2oTs5LdrjyrUFuNxdfq5hAg= -github.com/cloudwego/base64x v0.1.3/go.mod h1:1+1K5BUHIQzyapgpF7LwvOGAEDicKtt1umPV+aN8pi8= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= @@ -21,22 +20,22 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/free5gc/aper v1.0.6-0.20250102035630-3ddc831eed6a h1:PRapMdjqo96T7y8PHShUlirRDI0EaJNVrmdfQaHxOKY= github.com/free5gc/aper v1.0.6-0.20250102035630-3ddc831eed6a/go.mod h1:L4d0BJpHVOgiOC49aCz44mF0Vja3l+bcVSAs7i3CZ8s= -github.com/free5gc/nas v1.1.5 h1:Nn+ykQHcc3nHzsufvm/MwQjZRZV9/woxnPeoAMjgjP4= -github.com/free5gc/nas v1.1.5/go.mod h1:PjgawnhAVEMn/GRQw2FHkjRj0m2+9Bhbr1qrQPXCxwo= -github.com/free5gc/ngap v1.0.10 h1:Fj0EcmG+7m3yPKVwmtBPwJupj/dBmPxTG2BNljDSJXQ= -github.com/free5gc/ngap v1.0.10/go.mod h1:YB2lx46yopOOWi3dt/vEg198oHKUyQHo0qwenjdwhi4= -github.com/free5gc/openapi v1.1.0 h1:bOTp6vKC2MxupEXD76qeUL1MppV/SmXnka09JQJADZ0= -github.com/free5gc/openapi v1.1.0/go.mod h1:Q2vSmc1xpSE9Dy8rbNSWQwv7cFLHbZvKhq528vj6Wbg= -github.com/free5gc/sctp v1.0.1 h1:g8WDO97r8B9ubkT5Hyk9b4I1fZUOii9Z39gQ2eRaASo= -github.com/free5gc/sctp v1.0.1/go.mod h1:7QXfRWCmlkBGD0EIu3qL5o71bslfIakydz4h2QDZdjQ= -github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= -github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= +github.com/free5gc/nas v1.2.0 h1:pu0W1oDm2S8aeHdCo1n0zCbYu6R/ZTdZ/5lN3VYggMM= +github.com/free5gc/nas v1.2.0/go.mod h1:P8t/0Q3KnGQIEs+dTxXMHGh0aZ8CxC6NsCgrOXIEFW8= +github.com/free5gc/ngap v1.1.0 h1:MOcUYh+aix/Ow0ZN1W1EiwVpwTPbuuuKKlgHeEuxZMk= +github.com/free5gc/ngap v1.1.0/go.mod h1:SNeOmVtAg3Qf0alAG6d3r8CzHpf+2c9AXXoe380iauM= +github.com/free5gc/openapi v1.2.0 h1:AOPqkkiWK7XJPdzWVohWsoGkLBt8OrVkQkU7xzvzbek= +github.com/free5gc/openapi v1.2.0/go.mod h1:pGVJ27QZk4UGG4/1IioBtxwIKNdqOk7L9qcrXvdTjYU= +github.com/free5gc/sctp v1.1.0 h1:erxOTR49VOc8cc/fuqi8sscnCpl2/EvWG4CrFsbRoVc= +github.com/free5gc/sctp v1.1.0/go.mod h1:3pNCIh4roncSgvzIcBhSSsvZGRrMZNiqAVW3qzSE+cw= +github.com/free5gc/util v1.1.0 h1:W0gz5+9X/CdVv7VHAC2eU5mGsO8jsztvX3T+z3xXHhI= +github.com/free5gc/util v1.1.0/go.mod h1:33k3sojN/Vg+BbVmjfN3V8/5G/sboXS6OEOWWk7blqg= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -48,8 +47,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= -github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= @@ -96,8 +95,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg= -github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -149,8 +148,8 @@ go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= -golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= @@ -164,8 +163,8 @@ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/internal/gmm/handler.go b/internal/gmm/handler.go index 3d8232e1..d9440040 100644 --- a/internal/gmm/handler.go +++ b/internal/gmm/handler.go @@ -1030,7 +1030,7 @@ func communicateWithUDM(ue *context.AmfUe, accessType models.AccessType) error { problemDetails, err := consumer.GetConsumer().UeCmRegistration(ue, accessType, true) if problemDetails != nil { - return errors.Errorf(problemDetails.Cause) + return errors.Errorf("%s", problemDetails.Cause) } else if err != nil { return errors.Wrap(err, "UECM_Registration Error") } diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 701d4dc7..c2057fe9 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -119,7 +119,7 @@ func (s *nnrfService) SearchUdmSdmInstance( ue.NudmSDMUri = sdmUri if ue.NudmSDMUri == "" { err := fmt.Errorf("AMF can not select an UDM by NRF") - logger.ConsumerLog.Errorf(err.Error()) + logger.ConsumerLog.Error(err) return err } return nil From e78cc1f561f677c38e0acb3f781a5268216e5275 Mon Sep 17 00:00:00 2001 From: Alonza0314 Date: Thu, 17 Jul 2025 08:05:19 +0000 Subject: [PATCH 2/5] fix: build error --- internal/gmm/handler.go | 14 +++++++------- internal/ngap/handler.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/gmm/handler.go b/internal/gmm/handler.go index d9440040..d2c08b9f 100644 --- a/internal/gmm/handler.go +++ b/internal/gmm/handler.go @@ -1040,28 +1040,28 @@ func communicateWithUDM(ue *context.AmfUe, accessType models.AccessType) error { // using Nudm_SDM_Subscribe when the data requested is modified" problemDetails, err = consumer.GetConsumer().SDMGetAmData(ue) if problemDetails != nil { - return errors.Errorf(problemDetails.Cause) + return errors.Errorf("%s", problemDetails.Cause) } else if err != nil { return errors.Wrap(err, "SDM_Get AmData Error") } problemDetails, err = consumer.GetConsumer().SDMGetSmfSelectData(ue) if problemDetails != nil { - return errors.Errorf(problemDetails.Cause) + return errors.Errorf("%s", problemDetails.Cause) } else if err != nil { return errors.Wrap(err, "SDM_Get SmfSelectData Error") } problemDetails, err = consumer.GetConsumer().SDMGetUeContextInSmfData(ue) if problemDetails != nil { - return errors.Errorf(problemDetails.Cause) + return errors.Errorf("%s", problemDetails.Cause) } else if err != nil { return errors.Wrap(err, "SDM_Get UeContextInSmfData Error") } problemDetails, err = consumer.GetConsumer().SDMSubscribe(ue) if problemDetails != nil { - return errors.Errorf(problemDetails.Cause) + return errors.Errorf("%s", problemDetails.Cause) } else if err != nil { return errors.Wrap(err, "SDM Subscribe Error") } @@ -1669,7 +1669,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b } if ausfUri == "" { err = fmt.Errorf("AMF can not select an AUSF by NRF") - ue.GmmLog.Errorf(err.Error()) + ue.GmmLog.Error(err) gmm_message.SendRegistrationReject(ue.RanUe[accessType], nasMessage.Cause5GMMCongestion, "") return false, err } @@ -1680,7 +1680,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b ue.GmmLog.Errorf("Nausf_UEAU Authenticate Request Error: %+v", err) gmm_message.SendRegistrationReject(ue.RanUe[accessType], nasMessage.Cause5GMMCongestion, "") err = fmt.Errorf("Authentication procedure failed") - ue.GmmLog.Errorf(err.Error()) + ue.GmmLog.Error(err) return false, err } else if problemDetails != nil { ue.GmmLog.Warnf("Nausf_UEAU Authenticate Request Failed: %+v", problemDetails) @@ -1693,7 +1693,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b } gmm_message.SendRegistrationReject(ue.RanUe[accessType], cause, "") err = fmt.Errorf("Authentication procedure failed") - ue.GmmLog.Warnf(err.Error()) + ue.GmmLog.Warn(err) return false, err } ue.AuthenticationCtx = response diff --git a/internal/ngap/handler.go b/internal/ngap/handler.go index 973c7b5d..7134d564 100644 --- a/internal/ngap/handler.go +++ b/internal/ngap/handler.go @@ -106,7 +106,7 @@ func handleUplinkNASTransportMain(ran *context.AmfRan, if amfUe == nil { err := ranUe.Remove() if err != nil { - ran.Log.Errorf(err.Error()) + ran.Log.Error(err) } ran.Log.Errorf("No UE Context of RanUe with RANUENGAPID[%d] AMFUENGAPID[%d] ", ranUe.RanUeNgapId, ranUe.AmfUeNgapId) From d1092891b464935abb2da83cfc852508d03d580d Mon Sep 17 00:00:00 2001 From: Alonza0314 Date: Thu, 17 Jul 2025 08:28:09 +0000 Subject: [PATCH 3/5] fix: lint error --- .golangci.yml | 12 +++++++- internal/context/amf_ue.go | 5 ++-- internal/context/ran_ue.go | 5 ++-- internal/gmm/handler.go | 29 +++++++++--------- internal/gmm/message/build.go | 7 +++-- internal/gmm/message/send.go | 7 +++-- internal/nas/nas_security/security.go | 7 +++-- internal/ngap/handler.go | 2 +- internal/ngap/handler_test.go | 2 +- internal/ngap/message/build.go | 6 ++-- internal/sbi/processor/n1n2message.go | 8 ++--- internal/sbi/server.go | 7 +++-- pkg/factory/config.go | 42 +++++++++++++-------------- pkg/factory/config_test.go | 2 +- 14 files changed, 79 insertions(+), 62 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5d66091f..902a461e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,6 +38,16 @@ linters: - unused - whitespace settings: + staticcheck: + checks: + - all + - -QF1008 + - -SA1019 + - -ST1000 + - -ST1003 + - -ST1016 + - -ST1020 + - -ST1021 depguard: rules: main: @@ -51,7 +61,7 @@ linters: goconst: min-len: 5 min-occurrences: 3 - ignore-strings: get|post|put|delete|patch|options|head + ignore-string-values: get|post|put|delete|patch|options|head gocritic: disabled-checks: - regexpMust diff --git a/internal/context/amf_ue.go b/internal/context/amf_ue.go index 6d584e1d..c94c8986 100644 --- a/internal/context/amf_ue.go +++ b/internal/context/amf_ue.go @@ -340,9 +340,10 @@ func (ue *AmfUe) AttachRanUe(ranUe *RanUe) { func (ue *AmfUe) UpdateLogFields(accessType models.AccessType) { anTypeStr := "" - if accessType == models.AccessType__3_GPP_ACCESS { + switch accessType { + case models.AccessType__3_GPP_ACCESS: anTypeStr = "3GPP" - } else if accessType == models.AccessType_NON_3_GPP_ACCESS { + case models.AccessType_NON_3_GPP_ACCESS: anTypeStr = "Non3GPP" } if ranUe, ok := ue.RanUe[accessType]; ok { diff --git a/internal/context/ran_ue.go b/internal/context/ran_ue.go index e80ef47d..7a6bfe9b 100644 --- a/internal/context/ran_ue.go +++ b/internal/context/ran_ue.go @@ -133,9 +133,10 @@ func (ranUe *RanUe) UpdateLogFields() { } anTypeStr := "" - if ranUe.Ran.AnType == models.AccessType__3_GPP_ACCESS { + switch ranUe.Ran.AnType { + case models.AccessType__3_GPP_ACCESS: anTypeStr = "3GPP" - } else if ranUe.Ran.AnType == models.AccessType_NON_3_GPP_ACCESS { + case models.AccessType_NON_3_GPP_ACCESS: anTypeStr = "Non3GPP" } ranUe.Log = ranUe.Log.WithField(logger.FieldAmfUeNgapID, diff --git a/internal/gmm/handler.go b/internal/gmm/handler.go index d2c08b9f..b2a4dc7a 100644 --- a/internal/gmm/handler.go +++ b/internal/gmm/handler.go @@ -361,7 +361,7 @@ func forward5GSMMessageToSMF( ngap_message.AppendPDUSessionResourceToReleaseListRelCmd(&list, pduSessionID, n2SmInfo) ngap_message.SendPDUSessionResourceReleaseCommand(ue.RanUe[accessType], n1Msg, list) default: - return fmt.Errorf("Error N2 SM information type[%s]", responseData.N2SmInfoType) + return fmt.Errorf("error N2 SM information type[%s]", responseData.N2SmInfoType) } } else if n1Msg != nil { ue.GmmLog.Debugf("AMF forward Only N1 SM Message to UE") @@ -437,16 +437,16 @@ func HandleRegistrationRequest(ue *context.AmfUe, anType models.AccessType, proc ue.GmmLog.Infof("RegistrationType: Mobility Registration Updating") if ue.State[anType].Is(context.Deregistered) { gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMImplicitlyDeregistered, "") - return fmt.Errorf("Mobility Registration Updating was sent when the UE state was Deregistered") + return fmt.Errorf("mobility registration updating was sent when the UE state was deregistered") } case nasMessage.RegistrationType5GSPeriodicRegistrationUpdating: ue.GmmLog.Infof("RegistrationType: Periodic Registration Updating") if ue.State[anType].Is(context.Deregistered) { gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMImplicitlyDeregistered, "") - return fmt.Errorf("Periodic Registration Updating was sent when the UE state was Deregistered") + return fmt.Errorf("periodic registration updating was sent when the UE state was deregistered") } case nasMessage.RegistrationType5GSEmergencyRegistration: - return fmt.Errorf("Not Supportted RegistrationType: Emergency Registration") + return fmt.Errorf("not supported RegistrationType: Emergency Registration") case nasMessage.RegistrationType5GSReserved: ue.RegistrationType5GS = nasMessage.RegistrationType5GSInitialRegistration ue.GmmLog.Infof("RegistrationType: Reserved") @@ -544,7 +544,7 @@ func HandleRegistrationRequest(ue *context.AmfUe, anType models.AccessType, proc // Check TAI if !context.InTaiList(ue.Tai, amfSelf.SupportTaiLists) { gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMTrackingAreaNotAllowed, "") - return fmt.Errorf("Registration Reject[Tracking area not allowed]") + return fmt.Errorf("registration reject[tracking area not allowed]") } if registrationRequest.UESecurityCapability != nil { @@ -599,7 +599,7 @@ func contextTransferFromOldAmf(ue *context.AmfUe, anType models.AccessType, oldA // TODO 9a. After successful authentication in new AMF, which is triggered by the integrity check failure // in old AMF at step 5, the new AMF invokes step 4 above again and indicates that the UE is validated // (i.e. through the reason parameter as specified in clause 5.2.2.2.2). - return fmt.Errorf("Can not retrieve UE Context from old AMF[Cause: %s]", pd.Cause) + return fmt.Errorf("can not retrieve UE context from old AMF[cause: %s]", pd.Cause) } return fmt.Errorf("UE Context Transfer Request Failed Problem[%+v]", pd) } else if err != nil { @@ -1102,7 +1102,7 @@ func handleRequestedNssai(ue *context.AmfUe, anType models.AccessType) error { logger.GmmLog.Infof("RequestedNssai: %+v", ue.RegistrationRequest.RequestedNSSAI) requestedNssai, err := nasConvert.RequestedNssaiToModels(ue.RegistrationRequest.RequestedNSSAI) if err != nil { - return fmt.Errorf("Decode failed at RequestedNSSAI[%s]", err) + return fmt.Errorf("decode failed at RequestedNSSAI[%s]", err) } needSliceSelection := false @@ -1514,7 +1514,7 @@ func HandleIdentityResponse(ue *context.AmfUe, identityResponse *nasMessage.Iden return errors.New("empty Mobile Identity") } if nasConvert.GetTypeOfIdentity(mobileIdentityContents[0]) != ue.RequestIdentityType { - return fmt.Errorf("Received identity type doesn't match request type") + return fmt.Errorf("received identity type doesn't match request type") } if ue.T3570 != nil { @@ -1804,7 +1804,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, dlPduSessionId = N1N2ReqData.N2InfoContainer.SmInfo.PduSessionId } else { ue.N1N2Message = nil - return fmt.Errorf("Service Request triggered by Network has not implemented about non SM N2Info") + return fmt.Errorf("service request triggered by network has not implemented about non SM N2Info") } } } @@ -1858,7 +1858,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, smInfo := N1N2ReqData.N2InfoContainer.SmInfo smContext, ok := ue.SmContextFindByPDUSessionID(N1N2ReqData.PduSessionId) if !ok { - return fmt.Errorf("Service Request triggered by Network error for pduSession[%d] does not exist", + return fmt.Errorf("service request triggered by network error for pduSession[%d] does not exist", N1N2ReqData.PduSessionId) } @@ -1929,7 +1929,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, return err } default: - return fmt.Errorf("Service Type[%d] is not supported", serviceType) + return fmt.Errorf("service type[%d] is not supported", serviceType) } if len(errPduSessionId) != 0 { ue.GmmLog.Info(errPduSessionId, errCause) @@ -1947,7 +1947,7 @@ func HandleAuthenticationResponse(ue *context.AmfUe, accessType models.AccessTyp ue.StopT3560() if ue.AuthenticationCtx == nil { - return fmt.Errorf("Ue Authentication Context is nil") + return fmt.Errorf("ue authentication context is nil") } switch ue.AuthenticationCtx.AuthType { @@ -2089,7 +2089,8 @@ func HandleAuthenticationFailure(ue *context.AmfUe, anType models.AccessType, cause5GMM := authenticationFailure.Cause5GMM.GetCauseValue() - if ue.AuthenticationCtx.AuthType == models.AusfUeAuthenticationAuthType__5_G_AKA { + switch ue.AuthenticationCtx.AuthType { + case models.AusfUeAuthenticationAuthType__5_G_AKA: switch cause5GMM { case nasMessage.Cause5GMMMACFailure: ue.GmmLog.Warnln("Authentication Failure Cause: Mac Failure") @@ -2171,7 +2172,7 @@ func HandleAuthenticationFailure(ue *context.AmfUe, anType models.AccessType, gmm_message.SendAuthenticationRequest(ue.RanUe[anType]) } - } else if ue.AuthenticationCtx.AuthType == models.AusfUeAuthenticationAuthType_EAP_AKA_PRIME { + case models.AusfUeAuthenticationAuthType_EAP_AKA_PRIME: switch cause5GMM { case nasMessage.Cause5GMMngKSIAlreadyInUse: ue.GmmLog.Warn("Authentication Failure 5GMM Cause: NgKSI Already In Use") diff --git a/internal/gmm/message/build.go b/internal/gmm/message/build.go index d97350df..0ada66b7 100644 --- a/internal/gmm/message/build.go +++ b/internal/gmm/message/build.go @@ -462,9 +462,10 @@ func BuildDeregistrationRequest(ue *context.RanUe, accessType uint8, reRegistrat SecurityHeaderType: nas.SecurityHeaderTypeIntegrityProtectedAndCiphered, } var anType models.AccessType - if accessType == 0x01 { + switch accessType { + case 0x01: anType = models.AccessType__3_GPP_ACCESS - } else if accessType == 0x02 { + case 0x02: anType = models.AccessType_NON_3_GPP_ACCESS } if ue != nil { @@ -917,7 +918,7 @@ func BuildConfigurationUpdateCommand(ue *context.AmfUe, anType models.AccessType configurationUpdateCommand.UniversalTimeAndLocalTimeZone == nil && configurationUpdateCommand.LocalTimeZone == nil && configurationUpdateCommand.NetworkDaylightSavingTime == nil) { - return nil, fmt.Errorf("Configuration Update Command is invaild"), false + return nil, fmt.Errorf("configuration update command is invalid"), false } m.GmmMessage.ConfigurationUpdateCommand = configurationUpdateCommand diff --git a/internal/gmm/message/send.go b/internal/gmm/message/send.go index f129b305..65e3dba3 100644 --- a/internal/gmm/message/send.go +++ b/internal/gmm/message/send.go @@ -390,13 +390,14 @@ func SendDeregistrationRequest(ue *context.RanUe, accessType uint8, reRegistrati }, func() { amfUe.GmmLog.Warnf("T3522 Expires %d times, abort deregistration procedure", cfg.MaxRetryTimes) amfUe.T3522 = nil // clear the timer - if accessType == nasMessage.AccessType3GPP { + switch accessType { + case nasMessage.AccessType3GPP: amfUe.GmmLog.Warnln("UE accessType[3GPP] transfer to Deregistered state") amfUe.State[models.AccessType__3_GPP_ACCESS].Set(context.Deregistered) - } else if accessType == nasMessage.AccessTypeNon3GPP { + case nasMessage.AccessTypeNon3GPP: amfUe.GmmLog.Warnln("UE accessType[Non3GPP] transfer to Deregistered state") amfUe.State[models.AccessType_NON_3_GPP_ACCESS].Set(context.Deregistered) - } else { + default: amfUe.GmmLog.Warnln("UE accessType[3GPP] transfer to Deregistered state") amfUe.State[models.AccessType__3_GPP_ACCESS].Set(context.Deregistered) amfUe.GmmLog.Warnln("UE accessType[Non3GPP] transfer to Deregistered state") diff --git a/internal/nas/nas_security/security.go b/internal/nas/nas_security/security.go index c7fb682b..10297f05 100644 --- a/internal/nas/nas_security/security.go +++ b/internal/nas/nas_security/security.go @@ -381,11 +381,12 @@ func DecodePlainNasNoIntegrityCheck(payload []byte) (*nas.Message, error) { } func GetBearerType(accessType models.AccessType) uint8 { - if accessType == models.AccessType__3_GPP_ACCESS { + switch accessType { + case models.AccessType__3_GPP_ACCESS: return security.Bearer3GPP - } else if accessType == models.AccessType_NON_3_GPP_ACCESS { + case models.AccessType_NON_3_GPP_ACCESS: return security.BearerNon3GPP - } else { + default: return security.OnlyOneBearer } } diff --git a/internal/ngap/handler.go b/internal/ngap/handler.go index 7134d564..d74ee295 100644 --- a/internal/ngap/handler.go +++ b/internal/ngap/handler.go @@ -490,7 +490,7 @@ func handleInitialUEMessageMain(ran *context.AmfRan, // If id type is GUTI, since MAC can't be checked here (no amfUe context), the GUTI may not direct to the right amfUe. // In this case, create a new amfUe to handle the following registration procedure. - var isInvalidGUTI bool = (idType == "5G-GUTI") + isInvalidGUTI := (idType == "5G-GUTI") amfUe, ok := findAmfUe(ran, id, idType) if ok && !isInvalidGUTI { // TODO: invoke Namf_Communication_UEContextTransfer if serving AMF has changed since diff --git a/internal/ngap/handler_test.go b/internal/ngap/handler_test.go index 9bde0c72..52bfbb35 100644 --- a/internal/ngap/handler_test.go +++ b/internal/ngap/handler_test.go @@ -313,7 +313,7 @@ func BuildInitialUEMessage(ranUeNgapID int64, nasPdu []byte, fiveGSTmsi string) func TestHandleInitialUEMessage(t *testing.T) { var message *ngapType.NGAPPDU var ranUeNgapID int64 = 1 - var fiveGSTmsi string = "fe0000000001" + fiveGSTmsi := "fe0000000001" var msg ngapType.NGAPPDU testCases := []struct { diff --git a/internal/ngap/message/build.go b/internal/ngap/message/build.go index b2436fd2..1ec906d3 100644 --- a/internal/ngap/message/build.go +++ b/internal/ngap/message/build.go @@ -455,7 +455,7 @@ func BuildUEContextReleaseCommand( } switch causePresent { case ngapType.CausePresentNothing: - return nil, fmt.Errorf("Cause Present is Nothing") + return nil, fmt.Errorf("cause present is nothing") case ngapType.CausePresentRadioNetwork: ngapCause.RadioNetwork = new(ngapType.CauseRadioNetwork) ngapCause.RadioNetwork.Value = cause @@ -472,7 +472,7 @@ func BuildUEContextReleaseCommand( ngapCause.Misc = new(ngapType.CauseMisc) ngapCause.Misc.Value = cause default: - return nil, fmt.Errorf("Cause Present is Unknown") + return nil, fmt.Errorf("cause present is unknown") } ie.Value.Cause = &ngapCause @@ -2243,7 +2243,7 @@ func BuildPaging( taiListForPaging := ie.Value.TAIListForPaging if ue.RegistrationArea[models.AccessType__3_GPP_ACCESS] == nil { - err = fmt.Errorf("Registration Area of Ue[%s] is empty", ue.Supi) + err = fmt.Errorf("registration area of Ue[%s] is empty", ue.Supi) return nil, err } else { for _, tai := range ue.RegistrationArea[models.AccessType__3_GPP_ACCESS] { diff --git a/internal/sbi/processor/n1n2message.go b/internal/sbi/processor/n1n2message.go index 92d5ea07..87e13a38 100644 --- a/internal/sbi/processor/n1n2message.go +++ b/internal/sbi/processor/n1n2message.go @@ -73,15 +73,15 @@ func (p *Processor) N1N2MessageTransferProcedure(ueContextID string, reqUri stri transferErr *models.N1N2MessageTransferError, ) { var ( - requestData *models.N1N2MessageTransferReqData = n1n2MessageTransferRequest.JsonData - n2Info []byte = n1n2MessageTransferRequest.BinaryDataN2Information - n1Msg []byte = n1n2MessageTransferRequest.BinaryDataN1Message + requestData = n1n2MessageTransferRequest.JsonData + n2Info = n1n2MessageTransferRequest.BinaryDataN2Information + n1Msg = n1n2MessageTransferRequest.BinaryDataN1Message ue *context.AmfUe ok bool smContext *context.SmContext n1MsgType uint8 - anType models.AccessType = models.AccessType__3_GPP_ACCESS + anType = models.AccessType__3_GPP_ACCESS ) amfSelf := context.GetSelf() diff --git a/internal/sbi/server.go b/internal/sbi/server.go index c7b9e7e2..e1457f2c 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -170,13 +170,14 @@ func (s *Server) startServer(wg *sync.WaitGroup) { var err error cfg := s.Config() scheme := cfg.GetSbiScheme() - if scheme == "http" { + switch scheme { + case "http": err = s.httpServer.ListenAndServe() - } else if scheme == "https" { + case "https": err = s.httpServer.ListenAndServeTLS( cfg.GetCertPemPath(), cfg.GetCertKeyPath()) - } else { + default: err = fmt.Errorf("no support this scheme[%s]", scheme) } diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 5cd9e3c0..099f5094 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -145,19 +145,19 @@ func (c *Configuration) validate() (bool, error) { } mcc := v.PlmnId.Mcc if result := govalidator.StringMatches(mcc, "^[0-9]{3}$"); !result { - err := fmt.Errorf("Invalid mcc: %s, should be a 3-digit number", mcc) + err := fmt.Errorf("invalid mcc: %s, should be a 3-digit number", mcc) errs = append(errs, err) } mnc := v.PlmnId.Mnc if result := govalidator.StringMatches(mnc, "^[0-9]{2,3}$"); !result { - err := fmt.Errorf("Invalid mnc: %s, should be a 2 or 3-digit number", mnc) + err := fmt.Errorf("invalid mnc: %s, should be a 2 or 3-digit number", mnc) errs = append(errs, err) } amfId := v.AmfId if result := govalidator.StringMatches(amfId, "^[A-Fa-f0-9]{6}$"); !result { - err := fmt.Errorf("Invalid amfId: %s,"+ + err := fmt.Errorf("invalid amfId: %s,"+ " should be 3 bytes hex string, range: 000000~FFFFFF", amfId) errs = append(errs, err) } @@ -175,19 +175,19 @@ func (c *Configuration) validate() (bool, error) { } mcc := v.PlmnId.Mcc if result := govalidator.StringMatches(mcc, "^[0-9]{3}$"); !result { - err := fmt.Errorf("Invalid mcc: %s, should be a 3-digit number", mcc) + err := fmt.Errorf("invalid mcc: %s, should be a 3-digit number", mcc) errs = append(errs, err) } mnc := v.PlmnId.Mnc if result := govalidator.StringMatches(mnc, "^[0-9]{2,3}$"); !result { - err := fmt.Errorf("Invalid mnc: %s, should be a 2 or 3-digit number", mnc) + err := fmt.Errorf("invalid mnc: %s, should be a 2 or 3-digit number", mnc) errs = append(errs, err) } tac := v.Tac if result := govalidator.StringMatches(tac, "^[A-Fa-f0-9]{6}$"); !result { - err := fmt.Errorf("Invalid tac: %s, should be 3 bytes hex string, range: 000000~FFFFFF", tac) + err := fmt.Errorf("invalid tac: %s, should be 3 bytes hex string, range: 000000~FFFFFF", tac) errs = append(errs, err) } } @@ -335,7 +335,7 @@ func (s *Security) validate() (bool, error) { if s.IntegrityOrder != nil { for _, val := range s.IntegrityOrder { if result := govalidator.Contains(val, "NIA"); !result { - err := fmt.Errorf("Invalid integrityOrder: %s, should be NIA-series integrity algorithms", val) + err := fmt.Errorf("invalid integrityOrder: %s, should be NIA-series integrity algorithms", val) errs = append(errs, err) } } @@ -343,7 +343,7 @@ func (s *Security) validate() (bool, error) { if s.CipheringOrder != nil { for _, val := range s.CipheringOrder { if result := govalidator.Contains(val, "NEA"); !result { - err := fmt.Errorf("Invalid cipheringOrder: %s, should be NEA-series ciphering algorithms", val) + err := fmt.Errorf("invalid cipheringOrder: %s, should be NEA-series ciphering algorithms", val) errs = append(errs, err) } } @@ -370,7 +370,7 @@ func (p *PlmnSupportItem) validate() (bool, error) { mcc := p.PlmnId.Mcc if result := govalidator.StringMatches(mcc, "^[0-9]{3}$"); !result { - err := fmt.Errorf("Invalid mcc: %s, should be a 3-digit number", mcc) + err := fmt.Errorf("invalid mcc: %s, should be a 3-digit number", mcc) errs = append(errs, err) } @@ -419,19 +419,19 @@ func (l *Ladn) validate() (bool, error) { } mcc := v.PlmnId.Mcc if result := govalidator.StringMatches(mcc, "^[0-9]{3}$"); !result { - err := fmt.Errorf("Invalid mcc: %s, should be a 3-digit number", mcc) + err := fmt.Errorf("invalid mcc: %s, should be a 3-digit number", mcc) errs = append(errs, err) } mnc := v.PlmnId.Mnc if result := govalidator.StringMatches(mnc, "^[0-9]{2,3}$"); !result { - err := fmt.Errorf("Invalid mnc: %s, should be a 2 or 3-digit number", mnc) + err := fmt.Errorf("invalid mnc: %s, should be a 2 or 3-digit number", mnc) errs = append(errs, err) } tac := v.Tac if result := govalidator.StringMatches(tac, "^[A-Fa-f0-9]{6}$"); !result { - err := fmt.Errorf("Invalid tac: %s, should be 3 bytes hex string, range: 000000~FFFFFF", tac) + err := fmt.Errorf("invalid tac: %s, should be 3 bytes hex string, range: 000000~FFFFFF", tac) errs = append(errs, err) } } @@ -587,35 +587,35 @@ func (f *NetworkFeatureSupport5GS) validate() (bool, error) { var errs govalidator.Errors if result := govalidator.InRangeInt(f.Length, 1, 3); !result { - err := fmt.Errorf("Invalid length: %d, should be in the range of 1~3", f.Length) + err := fmt.Errorf("invalid length: %d, should be in the range of 1~3", f.Length) errs = append(errs, err) } if result := govalidator.InRangeInt(f.ImsVoPS, 0, 1); !result { - err := fmt.Errorf("Invalid imsVoPS: %d, should be in the range of 0~1", f.ImsVoPS) + err := fmt.Errorf("invalid imsVoPS: %d, should be in the range of 0~1", f.ImsVoPS) errs = append(errs, err) } if result := govalidator.InRangeInt(f.Emc, 0, 3); !result { - err := fmt.Errorf("Invalid emc: %d, should be in the range of 0~3", f.Emc) + err := fmt.Errorf("invalid emc: %d, should be in the range of 0~3", f.Emc) errs = append(errs, err) } if result := govalidator.InRangeInt(f.Emf, 0, 3); !result { - err := fmt.Errorf("Invalid emf: %d, should be in the range of 0~3", f.Emf) + err := fmt.Errorf("invalid emf: %d, should be in the range of 0~3", f.Emf) errs = append(errs, err) } if result := govalidator.InRangeInt(f.IwkN26, 0, 1); !result { - err := fmt.Errorf("Invalid iwkN26: %d, should be in the range of 0~1", f.IwkN26) + err := fmt.Errorf("invalid iwkN26: %d, should be in the range of 0~1", f.IwkN26) errs = append(errs, err) } if result := govalidator.InRangeInt(f.Mpsi, 0, 1); !result { - err := fmt.Errorf("Invalid mpsi: %d, should be in the range of 0~1", f.Mpsi) + err := fmt.Errorf("invalid mpsi: %d, should be in the range of 0~1", f.Mpsi) errs = append(errs, err) } if result := govalidator.InRangeInt(f.EmcN3, 0, 1); !result { - err := fmt.Errorf("Invalid emcN3: %d, should be in the range of 0~1", f.EmcN3) + err := fmt.Errorf("invalid emcN3: %d, should be in the range of 0~1", f.EmcN3) errs = append(errs, err) } if result := govalidator.InRangeInt(f.Mcsi, 0, 1); !result { - err := fmt.Errorf("Invalid mcsi: %d, should be in the range of 0~1", f.Mcsi) + err := fmt.Errorf("invalid mcsi: %d, should be in the range of 0~1", f.Mcsi) errs = append(errs, err) } if _, err := govalidator.ValidateStruct(f); err != nil { @@ -652,7 +652,7 @@ func appendInvalid(err error) error { es := err.(govalidator.Errors).Errors() for _, e := range es { - errs = append(errs, fmt.Errorf("Invalid %w", e)) + errs = append(errs, fmt.Errorf("invalid %w", e)) } return error(errs) diff --git a/pkg/factory/config_test.go b/pkg/factory/config_test.go index a0f460d6..c6354482 100644 --- a/pkg/factory/config_test.go +++ b/pkg/factory/config_test.go @@ -98,7 +98,7 @@ func TestSctp_validate(t *testing.T) { return } if tt.wantErr { - var errs govalidator.Errors = err.(govalidator.Errors) + errs := err.(govalidator.Errors) if len(errs) != tt.numErr { t.Errorf("Sctp.validate() error = %v, wantErr %v", err, tt.wantErr) return From 56db59fd4ce4fc956b3406c4170ddc2adc19a605 Mon Sep 17 00:00:00 2001 From: Alonza0314 Date: Thu, 17 Jul 2025 08:31:20 +0000 Subject: [PATCH 4/5] fix: lint config --- .golangci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 902a461e..503f088c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -61,7 +61,14 @@ linters: goconst: min-len: 5 min-occurrences: 3 - ignore-string-values: get|post|put|delete|patch|options|head + ignore-string-values: + - get + - post + - put + - delete + - patch + - options + - head gocritic: disabled-checks: - regexpMust From 2a911244300087e994a9b2ff417157a8b385975e Mon Sep 17 00:00:00 2001 From: Alonza0314 Date: Thu, 17 Jul 2025 10:13:28 +0000 Subject: [PATCH 5/5] chore: update mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3c90c0f2..d2287027 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/free5gc/ngap v1.1.0 github.com/free5gc/openapi v1.2.0 github.com/free5gc/sctp v1.1.0 - github.com/free5gc/util v1.1.0 + github.com/free5gc/util v1.1.1 github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/mitchellh/mapstructure v1.5.0 diff --git a/go.sum b/go.sum index a34fefb3..0a2d2b8d 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/free5gc/openapi v1.2.0 h1:AOPqkkiWK7XJPdzWVohWsoGkLBt8OrVkQkU7xzvzbek github.com/free5gc/openapi v1.2.0/go.mod h1:pGVJ27QZk4UGG4/1IioBtxwIKNdqOk7L9qcrXvdTjYU= github.com/free5gc/sctp v1.1.0 h1:erxOTR49VOc8cc/fuqi8sscnCpl2/EvWG4CrFsbRoVc= github.com/free5gc/sctp v1.1.0/go.mod h1:3pNCIh4roncSgvzIcBhSSsvZGRrMZNiqAVW3qzSE+cw= -github.com/free5gc/util v1.1.0 h1:W0gz5+9X/CdVv7VHAC2eU5mGsO8jsztvX3T+z3xXHhI= -github.com/free5gc/util v1.1.0/go.mod h1:33k3sojN/Vg+BbVmjfN3V8/5G/sboXS6OEOWWk7blqg= +github.com/free5gc/util v1.1.1 h1:gsjyI/XbHC9EChoMayHvV5kd92vDmp5/TvmBsOuHto4= +github.com/free5gc/util v1.1.1/go.mod h1:numtzcUQDVMpotUjwAXgGHqHHyPWKiicZhQtW4Ijk18= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=