diff --git a/.golangci.yml b/.golangci.yml index 02ed57d6c0204fbd95b605c882c909f422dcfce5..a642306620d7008f400e2c56a102c26d56d0870d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,35 +1,24 @@ -# This file contains all available configuration options -# with their default values. + # options for analysis running run: - # default concurrency is a available CPU number + # 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 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: - # 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 - # from 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: - # default is true. Enables skipping of directories: - # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ - skip-dirs-use-default: true - # 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: - # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + 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 @@ -37,20 +26,46 @@ 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: readonly|release|vendor + # + # Allowed values: readonly|vendor|mod + # Default: "" + # modules-download-mode: readonly + # Allow multiple parallel golangci-lint instances running. - # If false (default) - golangci-lint acquires file lock on start. + # 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" - format: colored-line-number + formats: + - format: "colored-line-number" + 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 + sort-order: + - linter + - severity + - file # filepath, line, and column. + show-stats: true + # all available settings of specific linters linters-settings: errcheck: @@ -67,26 +82,22 @@ linters-settings: # 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 - funlen: - lines: 60 - statements: 40 - gocognit: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 10 - nestif: - # minimal complexity of if statements to report, 5 by default - min-complexity: 4 + goconst: # minimal length of string constant, 3 by default - min-len: 3 - # minimal occurrences count to trigger, 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: + enabled-checks: [] #- rangeValCopy # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty disabled-checks: @@ -94,17 +105,31 @@ linters-settings: # 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: # settings passed to gocritic + + # 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: - sizeThreshold: 32 - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 10 + # 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 @@ -116,167 +141,176 @@ linters-settings: #- 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 - goimports: - # put imports beginning with prefix after 3rd-party packages; - # it's a comma-separated list of prefixes - local-prefixes: github.com/org/project - golint: - # minimal confidence for issues, default is 0.8 - min-confidence: 0.8 - gomnd: - settings: - mnd: - # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. - checks: argument,case,condition,operation,return,assign - gomodguard: - allowed: - modules: # List of allowed modules - # - gopkg.in/yaml.v2 - domains: # List of allowed module domains - # - golang.org - blocked: - modules: # List of blocked modules - # - github.com/uudashr/go-module: # Blocked module - # recommendations: # Recommended modules that should be used instead (Optional) - # - golang.org/x/mod - # reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional) - versions: # List of blocked module version constraints - # - github.com/mitchellh/go-homedir: # Blocked module with version constraint - # version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons - # reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional) + + # TODO + # golint: + # # minimal confidence for issues, default is 0.8 + # min-confidence: 0.8 + + # TODO + # gomnd: + # settings: + # mnd: + # # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. + # checks: argument,case,condition,operation,return,assign + govet: - # report about shadowed variables - check-shadowing: true + enable-all: false + # enable or disable analyzers by name + enable: + - atomicalign + - shadow + - printf + # settings per analyzer settings: - printf: # analyzer name, run `go tool vet help` to see all analyzers + # 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 - # enable or disable analyzers by name - enable: - - atomicalign - enable-all: false - disable: - - shadow - disable-all: false + shadow: + # Whether to be strict about shadowing; can be noisy. + # Default: false + strict: true + depguard: - list-type: blacklist - include-go-root: false - packages: - - github.com/sirupsen/logrus - packages-with-error-message: - # specify an error message to output when a blacklisted package is used - - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + 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 - maligned: - # print struct with more effective memory layout or not, false by default - suggest-new: true + + # Deprecate + # maligned: + # # print struct with more effective memory layout or not, false by default + # suggest-new: true + 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: - # 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 + # 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) - section-separators: - - newLine + + # 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: - wsl: - # If true append is only allowed to be cuddled if appending value is - # matching variables, fields or types on line above. Default is true. - strict-append: true - # Allow calls and assignments to be cuddled as long as the lines have any - # matching variables, fields or types. Default is true. - allow-assign-and-call: true - # Allow multiline assignments to be cuddled. Default is true. - allow-multiline-assign: true - # Allow declarations (var) to be cuddled. - allow-cuddle-declarations: false - # Allow trailing comments in ending of blocks - allow-trailing-comment: true - # Force newlines in end of case at this limit (0 = never). - force-case-trailing-whitespace: 0 - # Force cuddling of err checks with err var assignment - force-err-cuddling: false - # Allow leading comments to be separated with empty liens - allow-separated-leading-comment: false - custom: + locale: US + ignore-words: [] + + # custom: # Each custom linter should have a unique name. linters: + disable-all: true enable: + - errcheck + - goconst + - gocritic + - godox - gofmt - govet - - errcheck + - lll + - nakedret + - testpackage - staticcheck - unused + - whitespace + - gci + - misspell - gosimple - - structcheck - - varcheck + - ineffassign - - deadcode - typecheck - # Additional - - lll - - godox - # - gomnd - # - goconst - # - gocognit - # - maligned - # - nestif - # - gomodguard - - nakedret - # - golint - - gci - - misspell - gofumpt - - whitespace - unconvert - predeclared - noctx - dogsled - bodyclose - asciicheck + + # - structcheck # Deprecate + # - varcheck # Deprecate + # - deadcode # Deprecate + # - gomnd + # - maligned # - stylecheck # - unparam - # - wsl - #disable-all: false + # Enable only fast linters from enabled linters set (first run won't be fast) + # Default: false fast: true + + 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: + exclude: [] # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: + 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 @@ -287,7 +321,7 @@ issues: # 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: + 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 diff --git a/backend/WebUI/api_charging.go b/backend/WebUI/api_charging.go index 22db196ee14d16390a8636550c9ca02e6471a7c2..e706a80f757e846c5ada97080aff0ea2ce6b90d8 100644 --- a/backend/WebUI/api_charging.go +++ b/backend/WebUI/api_charging.go @@ -21,6 +21,11 @@ import ( "github.com/free5gc/webconsole/backend/webui_context" ) +const ( + ChargingOffline = "Offline" + ChargingOnline = "Online" +) + // Get vol from CDR // TS 32.297: Charging Data Record (CDR) file format and transfer func parseCDR(supi string) (map[int64]RatingGroupDataUsage, error) { @@ -84,7 +89,7 @@ func GetChargingData(c *gin.Context) { } logger.BillingLog.Traceln(chargingMethod) - if chargingMethod != "Offline" && chargingMethod != "Online" { + if chargingMethod != ChargingOffline && chargingMethod != ChargingOnline { c.JSON(http.StatusBadRequest, gin.H{"cause": "not support chargingMethod" + chargingMethod}) return } @@ -176,9 +181,9 @@ func GetChargingRecord(c *gin.Context) { "ueId": supi, "ratingGroup": rg, } - chargingDataInterface, err := mongoapi.RestfulAPIGetOne(chargingDataColl, filter) - if err != nil { - logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) + chargingDataInterface, err_get := mongoapi.RestfulAPIGetOne(chargingDataColl, filter) + if err_get != nil { + logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_get) } if len(chargingDataInterface) == 0 { logger.BillingLog.Warningf("ratingGroup: %d not found in mongoapi, may change the rg id", rg) @@ -193,10 +198,10 @@ func GetChargingRecord(c *gin.Context) { logger.BillingLog.Debugf("add ratingGroup: %d, supi: %s, method: %s", rg, supi, chargingData.ChargingMethod) switch chargingData.ChargingMethod { - case "Offline": - unitcost, err := strconv.ParseInt(chargingData.UnitCost, 10, 64) - if err != nil { - logger.BillingLog.Error("Offline unitCost strconv: ", err.Error()) + case ChargingOffline: + unitcost, err_parse := strconv.ParseInt(chargingData.UnitCost, 10, 64) + if err_parse != nil { + logger.BillingLog.Error("Offline unitCost strconv: ", err_parse.Error()) unitcost = 1 } @@ -218,7 +223,7 @@ func GetChargingRecord(c *gin.Context) { pdu_level.unitcost = unitcost } offlineChargingSliceTypeMap[key] = pdu_level - case "Online": + case ChargingOnline: tmpInt, err1 := strconv.Atoi(chargingData.Quota) if err1 != nil { logger.BillingLog.Error("Quota strconv: ", err1, rg, du, chargingData) diff --git a/backend/WebUI/api_verify.go b/backend/WebUI/api_verify.go index 27ad8eb195b5784ddcb5424479b6b8954131d069..174cee9d959fb002882ed3cc246c5c8aa1f47223 100644 --- a/backend/WebUI/api_verify.go +++ b/backend/WebUI/api_verify.go @@ -40,15 +40,15 @@ func GetSmfUserPlaneInfo() (interface{}, error) { // TODO: support fetching data from multiple SMF if smfUris := webuiSelf.GetOamUris(models.NfType_SMF); smfUris != nil { requestUri := fmt.Sprintf("%s/nsmf-oam/v1/user-plane-info/", smfUris[0]) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil) - if err != nil { - logger.ProcLog.Error(err) - return jsonData, err + req, err_req := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil) + if err_req != nil { + logger.ProcLog.Error(err_req) + return jsonData, err_req } - resp, err := httpsClient.Do(req) - if err != nil { - logger.ProcLog.Error(err) - return jsonData, err + resp, err_rsp := httpsClient.Do(req) + if err_rsp != nil { + logger.ProcLog.Error(err_rsp) + return jsonData, err_rsp } defer func() { if closeErr := resp.Body.Close(); closeErr != nil { diff --git a/backend/WebUI/api_webui.go b/backend/WebUI/api_webui.go index 6e2d453a51a98e0bbb3799473a2cc8dca8180391..38496868680e25fe3c7d8acee9923830dc1fc01c 100644 --- a/backend/WebUI/api_webui.go +++ b/backend/WebUI/api_webui.go @@ -713,7 +713,7 @@ func PutTenantByID(c *gin.Context) { } var tenantData Tenant - if err := c.ShouldBindJSON(&tenantData); err != nil { + if err = c.ShouldBindJSON(&tenantData); err != nil { c.JSON(http.StatusBadRequest, gin.H{}) return } @@ -721,8 +721,8 @@ func PutTenantByID(c *gin.Context) { tenantBsonM := toBsonM(tenantData) filterTenantIdOnly = bson.M{"tenantId": tenantId} - if _, err := mongoapi.RestfulAPIPost(tenantDataColl, filterTenantIdOnly, tenantBsonM); err != nil { - logger.ProcLog.Errorf("PutTenantByID err: %+v", err) + if _, err_post := mongoapi.RestfulAPIPost(tenantDataColl, filterTenantIdOnly, tenantBsonM); err_post != nil { + logger.ProcLog.Errorf("PutTenantByID err: %+v", err_post) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -894,8 +894,8 @@ func PostUserByID(c *gin.Context) { userBsonM := toBsonM(userData) filterUserIdOnly := bson.M{"tenantId": userData.TenantId, "userId": userData.UserId} - if _, err := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err != nil { - logger.ProcLog.Errorf("PostUserByID err: %+v", err) + if _, err_post := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err_post != nil { + logger.ProcLog.Errorf("PostUserByID err: %+v", err_post) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -946,9 +946,9 @@ func PutUserByID(c *gin.Context) { if newUserData.Email != "" && newUserData.Email != userData.Email { filterEmail := bson.M{"email": newUserData.Email} - sameEmailInterface, err := mongoapi.RestfulAPIGetOne(userDataColl, filterEmail) - if err != nil { - logger.ProcLog.Errorf("PutUserByID err: %+v", err) + sameEmailInterface, err_get := mongoapi.RestfulAPIGetOne(userDataColl, filterEmail) + if err_get != nil { + logger.ProcLog.Errorf("PutUserByID err: %+v", err_get) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -960,9 +960,9 @@ func PutUserByID(c *gin.Context) { } if newUserData.EncryptedPassword != "" { - hash, err := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) - if err != nil { - logger.ProcLog.Errorf("PutUserByID err: %+v", err) + hash, err_gen := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) + if err_gen != nil { + logger.ProcLog.Errorf("PutUserByID err: %+v", err_gen) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -970,8 +970,8 @@ func PutUserByID(c *gin.Context) { } userBsonM := toBsonM(userData) - if _, err := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err != nil { - logger.ProcLog.Errorf("PutUserByID err: %+v", err) + if _, err_post := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err_post != nil { + logger.ProcLog.Errorf("PutUserByID err: %+v", err_post) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -1035,16 +1035,15 @@ func GetSubscribers(c *gin.Context) { tenantId := amData["tenantId"] filterUeIdOnly := bson.M{"ueId": ueId} - authSubsDataInterface, err := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) - if err != nil { - logger.ProcLog.Errorf("GetSubscribers err: %+v", err) + authSubsDataInterface, err_get := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) + if err_get != nil { + logger.ProcLog.Errorf("GetSubscribers err: %+v", err_get) c.JSON(http.StatusInternalServerError, gin.H{}) return } var authSubsData AuthSub - err = json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData) - if err != nil { + if err = json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData); err != nil { logger.ProcLog.Errorf("GetSubscribers err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return @@ -1140,55 +1139,55 @@ func GetSubscriberByID(c *gin.Context) { } var authSubsData models.AuthenticationSubscription - if err := json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData); err != nil { + if err = json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var amDataData models.AccessAndMobilitySubscriptionData - if err := json.Unmarshal(mapToByte(amDataDataInterface), &amDataData); err != nil { + if err = json.Unmarshal(mapToByte(amDataDataInterface), &amDataData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var smDataData []models.SessionManagementSubscriptionData - if err := json.Unmarshal(sliceToByte(smDataDataInterface), &smDataData); err != nil { + if err = json.Unmarshal(sliceToByte(smDataDataInterface), &smDataData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var smfSelData models.SmfSelectionSubscriptionData - if err := json.Unmarshal(mapToByte(smfSelDataInterface), &smfSelData); err != nil { + if err = json.Unmarshal(mapToByte(smfSelDataInterface), &smfSelData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var amPolicyData models.AmPolicyData - if err := json.Unmarshal(mapToByte(amPolicyDataInterface), &amPolicyData); err != nil { + if err = json.Unmarshal(mapToByte(amPolicyDataInterface), &amPolicyData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var smPolicyData models.SmPolicyData - if err := json.Unmarshal(mapToByte(smPolicyDataInterface), &smPolicyData); err != nil { + if err = json.Unmarshal(mapToByte(smPolicyDataInterface), &smPolicyData); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var flowRules []FlowRule - if err := json.Unmarshal(sliceToByte(flowRuleDataInterface), &flowRules); err != nil { + if err = json.Unmarshal(sliceToByte(flowRuleDataInterface), &flowRules); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var qosFlows []QosFlow - if err := json.Unmarshal(sliceToByte(qosFlowInterface), &qosFlows); err != nil { + if err = json.Unmarshal(sliceToByte(qosFlowInterface), &qosFlows); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return } var chargingDatas []ChargingData - if err := json.Unmarshal(sliceToByte(chargingDatasInterface), &chargingDatas); err != nil { + if err = json.Unmarshal(sliceToByte(chargingDatasInterface), &chargingDatas); err != nil { logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err) c.JSON(http.StatusInternalServerError, gin.H{}) return @@ -1327,9 +1326,9 @@ func PostSubscriberByID(c *gin.Context) { // Lookup same UE ID of other tenant's subscription. if claims != nil { - authSubsDataInterface, err := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) - if err != nil { - logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) + authSubsDataInterface, err_get := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) + if err_get != nil { + logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_get) c.JSON(http.StatusInternalServerError, gin.H{}) return } @@ -1536,7 +1535,7 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub chargingDataBsonM := toBsonM(chargingData) // Clear quota for offline charging flow - if chargingData.ChargingMethod == "Offline" { + if chargingData.ChargingMethod == ChargingOffline { chargingDataBsonM["quota"] = "0" } @@ -1583,8 +1582,8 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub chargingDataBsonM["ueId"] = ueId chargingDataBsonM["servingPlmnId"] = servingPlmnId - if _, err := mongoapi.RestfulAPIPutOne(chargingDataColl, chargingFilter, chargingDataBsonM); err != nil { - logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) + if _, err_put := mongoapi.RestfulAPIPutOne(chargingDataColl, chargingFilter, chargingDataBsonM); err != nil { + logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_put) } } } @@ -1728,16 +1727,16 @@ func PatchSubscriberByID(c *gin.Context) { c.JSON(http.StatusNoContent, gin.H{}) } -func removeCdrFile(CdrFilePath string) { - files, err := filepath.Glob(CdrFilePath + "*.cdr") +func removeCdrFile(cdrFilePath string) { + files, err := filepath.Glob(cdrFilePath + "*.cdr") if err != nil { - logger.BillingLog.Warnf("CDR file not found in %s", CdrFilePath) + logger.BillingLog.Warnf("CDR file not found in %s", cdrFilePath) } for _, file := range files { - if _, err := os.Stat(file); err == nil { + if _, err = os.Stat(file); err == nil { logger.BillingLog.Infof("Remove CDR file: " + file) - if err := os.Remove(file); err != nil { + if err = os.Remove(file); err != nil { logger.BillingLog.Warnf("Failed to remove CDR file: %s\n", file) } } @@ -1907,16 +1906,16 @@ func ChangePasswordInfo(c *gin.Context) { } if newUserData.EncryptedPassword != "" { - hash, err := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) - if err != nil { - logger.ProcLog.Errorf("GenerateFromPassword err: %+v", err) + hash, err_gen := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) + if err_gen != nil { + logger.ProcLog.Errorf("GenerateFromPassword err: %+v", err_gen) } userData.EncryptedPassword = string(hash) } userBsonM := toBsonM(userData) - if _, err := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err != nil { - logger.ProcLog.Errorf("PutUserByID err: %+v", err) + if _, err_put := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err_put != nil { + logger.ProcLog.Errorf("PutUserByID err: %+v", err_put) } c.JSON(http.StatusOK, userData) diff --git a/backend/billing/client.go b/backend/billing/client.go index e042e215211233542209ae9e1ffa3b571b4ef82c..1b6bcb66530ae45ac8e067b88eddbfcabaa68683 100644 --- a/backend/billing/client.go +++ b/backend/billing/client.go @@ -41,18 +41,18 @@ func PullCDRFile(c *ftp.ServerConn, fileName string) ([]byte, error) { } defer func() { - if err := r.Close(); err != nil { + if err = r.Close(); err != nil { logger.BillingLog.Error(err) } }() logger.BillingLog.Info("Pull CDR file success") - if err := c.Quit(); err != nil { + if err = c.Quit(); err != nil { return nil, err } - cdr, err1 := io.ReadAll(r) + cdr, err_read := io.ReadAll(r) - return cdr, err1 + return cdr, err_read } diff --git a/backend/billing/server.go b/backend/billing/server.go index d31cb1d79cb3f0936fa29b7d849f147b87b6e80f..3b36b78df8006c1f2aef4ff6aaad93beb7946abf 100644 --- a/backend/billing/server.go +++ b/backend/billing/server.go @@ -50,8 +50,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { wg: wg, } if _, err := os.Stat("/tmp/webconsole"); err != nil { - if err := os.Mkdir("/tmp/webconsole", os.ModePerm); err != nil { - logger.BillingLog.Error(err) + if err_mk := os.Mkdir("/tmp/webconsole", os.ModePerm); err_mk != nil { + logger.BillingLog.Error(err_mk) } } @@ -90,8 +90,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { return nil } - if err := os.WriteFile(confFile, file, 0o600); err != nil { //nolint: gomnd - logger.BillingLog.Errorf("Couldn't create conf file %v", confFile) + if err = os.WriteFile(confFile, file, 0o600); err != nil { + logger.BillingLog.Errorf("Couldn't create conf file %v, err: %+v", confFile, err) return nil } diff --git a/backend/webui_context/nrf_management.go b/backend/webui_context/nrf_management.go index 1e6224f7d02f4acf7e44b455fcc248ca1ba73af7..f9ee9a0112a8f08f4710f2c2c2e99ab25b0bf3d3 100644 --- a/backend/webui_context/nrf_management.go +++ b/backend/webui_context/nrf_management.go @@ -75,9 +75,9 @@ func SendNFRegistration() error { return nil } -func RetrySendNFRegistration(MaxRetry int) error { +func RetrySendNFRegistration(maxRetry int) error { retryCount := 0 - for retryCount < MaxRetry { + for retryCount < maxRetry { err := SendNFRegistration() if err == nil { return nil