Skip to content
Snippets Groups Projects
Unverified Commit 92b7e4be authored by CTFang@WireLab's avatar CTFang@WireLab
Browse files

fix: update golagci-lint setting and fix linter error

parent f3f91f28
No related branches found
No related tags found
No related merge requests found
# This file contains all available configuration options
# with their default values.
# options for analysis running # options for analysis running
run: 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 concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m # timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 3m timeout: 3m
# exit code when at least one issue was found, default is 1 # exit code when at least one issue was found, default is 1
issues-exit-code: 1 issues-exit-code: 1
# include test files or not, default is true # include test files or not, default is true
tests: true tests: true
# list of build tags, all linters use it. Default is empty list. # list of build tags, all linters use it. Default is empty list.
build-tags: build-tags: []
# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path; # If set, we pass it to "go list -mod={option}". From "go help modules":
# 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":
# If invoked with -mod=readonly, the go command is disallowed from the implicit # 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 # 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 # to go.mod are needed. This setting is most useful to check that go.mod does
...@@ -37,20 +26,46 @@ run: ...@@ -37,20 +26,46 @@ run:
# If invoked with -mod=vendor, the go command assumes that the vendor # If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores # directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod. # 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. # 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-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 configuration options
output: output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" # 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 lines of code with issue, default is true
print-issued-lines: 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 is true
print-linter-name: true print-linter-name: true
# make issues output unique by line, default is true # make issues output unique by line, default is true
uniq-by-line: 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 # all available settings of specific linters
linters-settings: linters-settings:
errcheck: errcheck:
...@@ -67,26 +82,22 @@ linters-settings: ...@@ -67,26 +82,22 @@ linters-settings:
# path to a file containing a list of functions to exclude from checking # path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details # see https://github.com/kisielk/errcheck#excluding-functions for details
#exclude: /path/to/file.txt #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: goconst:
# minimal length of string constant, 3 by default # minimal length of string constant, 3 by default
min-len: 3 min-len: 5
# minimal occurrences count to trigger, 3 by default # Minimum occurrences of constant string count to trigger issue, 3 by default
min-occurrences: 3 min-occurrences: 3
# Exclude strings matching the given regular expression.
# Default: ""
ignore-strings: "get|post|put|delete|patch|options|head"
gocritic: gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks'; # Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview # See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used. # By default list of stable checks is used.
enabled-checks: enabled-checks: []
#- rangeValCopy #- rangeValCopy
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks: disabled-checks:
...@@ -94,17 +105,31 @@ linters-settings: ...@@ -94,17 +105,31 @@ linters-settings:
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. # 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". # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags: enabled-tags:
- diagnostic
- performance - performance
disabled-tags: disabled-tags:
- experimental - 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 captLocal: # must be valid enabled check name
# Whether to restrict checker to params only.
paramsOnly: true paramsOnly: true
rangeValCopy: rangeValCopy:
sizeThreshold: 32 # Size in bytes that makes the warning trigger. Default: 128
gocyclo: # This size shoulb be smaller
# minimal code complexity to report, 30 by default (but we recommend 10-20) sizeThreshold: 512
min-complexity: 10 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: godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that # 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 # might be left in the code accidentally and should be resolved before merging
...@@ -116,167 +141,176 @@ linters-settings: ...@@ -116,167 +141,176 @@ linters-settings:
#- OPTIMIZE # marks code that should be optimized before merging #- OPTIMIZE # marks code that should be optimized before merging
#- HACK # marks hack-arounds that should be removed before merging #- HACK # marks hack-arounds that should be removed before merging
- XXX # Fatal! Important problem - XXX # Fatal! Important problem
gofmt: gofmt:
# simplify code: gofmt with `-s` option, true by default # simplify code: gofmt with `-s` option, true by default
simplify: true simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages; # TODO
# it's a comma-separated list of prefixes # golint:
local-prefixes: github.com/org/project # # minimal confidence for issues, default is 0.8
golint: # min-confidence: 0.8
# minimal confidence for issues, default is 0.8
min-confidence: 0.8 # TODO
gomnd: # gomnd:
settings: # settings:
mnd: # mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. # # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign # 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)
govet: govet:
# report about shadowed variables enable-all: false
check-shadowing: true # enable or disable analyzers by name
enable:
- atomicalign
- shadow
- printf
# settings per analyzer # settings per analyzer
settings: 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 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).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - (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).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# enable or disable analyzers by name shadow:
enable: # Whether to be strict about shadowing; can be noisy.
- atomicalign # Default: false
enable-all: false strict: true
disable:
- shadow
disable-all: false
depguard: depguard:
list-type: blacklist rules:
include-go-root: false # Name of a rule.
packages: main:
- github.com/sirupsen/logrus # Used to determine the package matching priority.
packages-with-error-message: # There are three different modes: `original`, `strict`, and `lax`.
# specify an error message to output when a blacklisted package is used # Default: "original"
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" list-mode: original
deny:
- pkg: github.com/sirupsen/logrus
desc: "logging is allowed only by logutils.Log"
lll: lll:
# max line length, lines longer will be reported. Default is 120. # 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 # '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 120 line-length: 120
# tab width in spaces. Default to 1. # tab width in spaces. Default to 1.
tab-width: 1 tab-width: 1
maligned:
# print struct with more effective memory layout or not, false by default # Deprecate
suggest-new: true # maligned:
# # print struct with more effective memory layout or not, false by default
# suggest-new: true
nakedret: nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30 # 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 max-func-lines: 30
testpackage: testpackage:
# regexp pattern to skip files # regexp pattern to skip files
skip-regexp: (export|internal)_test\.go skip-regexp: (export|internal)_test\.go
unused: unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false. # Mark all struct fields that have been written to as used.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors: # Default: true
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations field-writes-are-uses: true
# with golangci-lint call it on a directory with the changed file. # Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write.
check-exported: false # 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: whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement 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 multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci: gci:
sections: sections:
- standard - standard
- default - default
- prefix(github.com/free5gc) - 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: misspell:
#locale: US locale: US
ignore-words: ignore-words: []
wsl:
# If true append is only allowed to be cuddled if appending value is # custom:
# 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:
# Each custom linter should have a unique name. # Each custom linter should have a unique name.
linters: linters:
disable-all: true
enable: enable:
- errcheck
- goconst
- gocritic
- godox
- gofmt - gofmt
- govet - govet
- errcheck - lll
- nakedret
- testpackage
- staticcheck - staticcheck
- unused - unused
- whitespace
- gci
- misspell
- gosimple - gosimple
- structcheck
- varcheck
- ineffassign - ineffassign
- deadcode
- typecheck - typecheck
# Additional
- lll
- godox
# - gomnd
# - goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
# - golint
- gci
- misspell
- gofumpt - gofumpt
- whitespace
- unconvert - unconvert
- predeclared - predeclared
- noctx - noctx
- dogsled - dogsled
- bodyclose - bodyclose
- asciicheck - asciicheck
# - structcheck # Deprecate
# - varcheck # Deprecate
# - deadcode # Deprecate
# - gomnd
# - maligned
# - stylecheck # - stylecheck
# - unparam # - unparam
# - wsl
#disable-all: false # Enable only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true fast: true
issues: issues:
# List of regexps of issue texts to exclude, empty list by default. # List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns, # But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all # it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help` # excluded by default patterns execute `golangci-lint run --help`
exclude: exclude: []
# Excluding configuration per-path, per-linter, per-text and per-source # Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules: exclude-rules: []
# Exclude some linters from running on tests files. # Exclude some linters from running on tests files.
# Independently from option `exclude` we use default exclude patterns, # Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all # it can be disabled by this option. To list all
...@@ -287,7 +321,7 @@ issues: ...@@ -287,7 +321,7 @@ issues:
# regular expressions become case sensitive. # regular expressions become case sensitive.
exclude-case-sensitive: false exclude-case-sensitive: false
# The list of ids of default excludes to include or disable. By default it's empty. # 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 #- EXC0002 # disable excluding of issues about comments from golint
# Maximum issues count per one linter. Set to 0 to disable. Default is 50. # Maximum issues count per one linter. Set to 0 to disable. Default is 50.
#max-issues-per-linter: 0 #max-issues-per-linter: 0
......
...@@ -21,6 +21,11 @@ import ( ...@@ -21,6 +21,11 @@ import (
"github.com/free5gc/webconsole/backend/webui_context" "github.com/free5gc/webconsole/backend/webui_context"
) )
const (
ChargingOffline = "Offline"
ChargingOnline = "Online"
)
// Get vol from CDR // Get vol from CDR
// TS 32.297: Charging Data Record (CDR) file format and transfer // TS 32.297: Charging Data Record (CDR) file format and transfer
func parseCDR(supi string) (map[int64]RatingGroupDataUsage, error) { func parseCDR(supi string) (map[int64]RatingGroupDataUsage, error) {
...@@ -84,7 +89,7 @@ func GetChargingData(c *gin.Context) { ...@@ -84,7 +89,7 @@ func GetChargingData(c *gin.Context) {
} }
logger.BillingLog.Traceln(chargingMethod) 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}) c.JSON(http.StatusBadRequest, gin.H{"cause": "not support chargingMethod" + chargingMethod})
return return
} }
...@@ -176,9 +181,9 @@ func GetChargingRecord(c *gin.Context) { ...@@ -176,9 +181,9 @@ func GetChargingRecord(c *gin.Context) {
"ueId": supi, "ueId": supi,
"ratingGroup": rg, "ratingGroup": rg,
} }
chargingDataInterface, err := mongoapi.RestfulAPIGetOne(chargingDataColl, filter) chargingDataInterface, err_get := mongoapi.RestfulAPIGetOne(chargingDataColl, filter)
if err != nil { if err_get != nil {
logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_get)
} }
if len(chargingDataInterface) == 0 { if len(chargingDataInterface) == 0 {
logger.BillingLog.Warningf("ratingGroup: %d not found in mongoapi, may change the rg id", rg) logger.BillingLog.Warningf("ratingGroup: %d not found in mongoapi, may change the rg id", rg)
...@@ -193,10 +198,10 @@ func GetChargingRecord(c *gin.Context) { ...@@ -193,10 +198,10 @@ func GetChargingRecord(c *gin.Context) {
logger.BillingLog.Debugf("add ratingGroup: %d, supi: %s, method: %s", rg, supi, chargingData.ChargingMethod) logger.BillingLog.Debugf("add ratingGroup: %d, supi: %s, method: %s", rg, supi, chargingData.ChargingMethod)
switch chargingData.ChargingMethod { switch chargingData.ChargingMethod {
case "Offline": case ChargingOffline:
unitcost, err := strconv.ParseInt(chargingData.UnitCost, 10, 64) unitcost, err_parse := strconv.ParseInt(chargingData.UnitCost, 10, 64)
if err != nil { if err_parse != nil {
logger.BillingLog.Error("Offline unitCost strconv: ", err.Error()) logger.BillingLog.Error("Offline unitCost strconv: ", err_parse.Error())
unitcost = 1 unitcost = 1
} }
...@@ -218,7 +223,7 @@ func GetChargingRecord(c *gin.Context) { ...@@ -218,7 +223,7 @@ func GetChargingRecord(c *gin.Context) {
pdu_level.unitcost = unitcost pdu_level.unitcost = unitcost
} }
offlineChargingSliceTypeMap[key] = pdu_level offlineChargingSliceTypeMap[key] = pdu_level
case "Online": case ChargingOnline:
tmpInt, err1 := strconv.Atoi(chargingData.Quota) tmpInt, err1 := strconv.Atoi(chargingData.Quota)
if err1 != nil { if err1 != nil {
logger.BillingLog.Error("Quota strconv: ", err1, rg, du, chargingData) logger.BillingLog.Error("Quota strconv: ", err1, rg, du, chargingData)
......
...@@ -40,15 +40,15 @@ func GetSmfUserPlaneInfo() (interface{}, error) { ...@@ -40,15 +40,15 @@ func GetSmfUserPlaneInfo() (interface{}, error) {
// TODO: support fetching data from multiple SMF // TODO: support fetching data from multiple SMF
if smfUris := webuiSelf.GetOamUris(models.NfType_SMF); smfUris != nil { if smfUris := webuiSelf.GetOamUris(models.NfType_SMF); smfUris != nil {
requestUri := fmt.Sprintf("%s/nsmf-oam/v1/user-plane-info/", smfUris[0]) requestUri := fmt.Sprintf("%s/nsmf-oam/v1/user-plane-info/", smfUris[0])
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil) req, err_req := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil)
if err != nil { if err_req != nil {
logger.ProcLog.Error(err) logger.ProcLog.Error(err_req)
return jsonData, err return jsonData, err_req
} }
resp, err := httpsClient.Do(req) resp, err_rsp := httpsClient.Do(req)
if err != nil { if err_rsp != nil {
logger.ProcLog.Error(err) logger.ProcLog.Error(err_rsp)
return jsonData, err return jsonData, err_rsp
} }
defer func() { defer func() {
if closeErr := resp.Body.Close(); closeErr != nil { if closeErr := resp.Body.Close(); closeErr != nil {
......
...@@ -713,7 +713,7 @@ func PutTenantByID(c *gin.Context) { ...@@ -713,7 +713,7 @@ func PutTenantByID(c *gin.Context) {
} }
var tenantData Tenant var tenantData Tenant
if err := c.ShouldBindJSON(&tenantData); err != nil { if err = c.ShouldBindJSON(&tenantData); err != nil {
c.JSON(http.StatusBadRequest, gin.H{}) c.JSON(http.StatusBadRequest, gin.H{})
return return
} }
...@@ -721,8 +721,8 @@ func PutTenantByID(c *gin.Context) { ...@@ -721,8 +721,8 @@ func PutTenantByID(c *gin.Context) {
tenantBsonM := toBsonM(tenantData) tenantBsonM := toBsonM(tenantData)
filterTenantIdOnly = bson.M{"tenantId": tenantId} filterTenantIdOnly = bson.M{"tenantId": tenantId}
if _, err := mongoapi.RestfulAPIPost(tenantDataColl, filterTenantIdOnly, tenantBsonM); err != nil { if _, err_post := mongoapi.RestfulAPIPost(tenantDataColl, filterTenantIdOnly, tenantBsonM); err_post != nil {
logger.ProcLog.Errorf("PutTenantByID err: %+v", err) logger.ProcLog.Errorf("PutTenantByID err: %+v", err_post)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -894,8 +894,8 @@ func PostUserByID(c *gin.Context) { ...@@ -894,8 +894,8 @@ func PostUserByID(c *gin.Context) {
userBsonM := toBsonM(userData) userBsonM := toBsonM(userData)
filterUserIdOnly := bson.M{"tenantId": userData.TenantId, "userId": userData.UserId} filterUserIdOnly := bson.M{"tenantId": userData.TenantId, "userId": userData.UserId}
if _, err := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err != nil { if _, err_post := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err_post != nil {
logger.ProcLog.Errorf("PostUserByID err: %+v", err) logger.ProcLog.Errorf("PostUserByID err: %+v", err_post)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -946,9 +946,9 @@ func PutUserByID(c *gin.Context) { ...@@ -946,9 +946,9 @@ func PutUserByID(c *gin.Context) {
if newUserData.Email != "" && newUserData.Email != userData.Email { if newUserData.Email != "" && newUserData.Email != userData.Email {
filterEmail := bson.M{"email": newUserData.Email} filterEmail := bson.M{"email": newUserData.Email}
sameEmailInterface, err := mongoapi.RestfulAPIGetOne(userDataColl, filterEmail) sameEmailInterface, err_get := mongoapi.RestfulAPIGetOne(userDataColl, filterEmail)
if err != nil { if err_get != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err) logger.ProcLog.Errorf("PutUserByID err: %+v", err_get)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -960,9 +960,9 @@ func PutUserByID(c *gin.Context) { ...@@ -960,9 +960,9 @@ func PutUserByID(c *gin.Context) {
} }
if newUserData.EncryptedPassword != "" { if newUserData.EncryptedPassword != "" {
hash, err := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) hash, err_gen := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12)
if err != nil { if err_gen != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err) logger.ProcLog.Errorf("PutUserByID err: %+v", err_gen)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -970,8 +970,8 @@ func PutUserByID(c *gin.Context) { ...@@ -970,8 +970,8 @@ func PutUserByID(c *gin.Context) {
} }
userBsonM := toBsonM(userData) userBsonM := toBsonM(userData)
if _, err := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err != nil { if _, err_post := mongoapi.RestfulAPIPost(userDataColl, filterUserIdOnly, userBsonM); err_post != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err) logger.ProcLog.Errorf("PutUserByID err: %+v", err_post)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -1035,16 +1035,15 @@ func GetSubscribers(c *gin.Context) { ...@@ -1035,16 +1035,15 @@ func GetSubscribers(c *gin.Context) {
tenantId := amData["tenantId"] tenantId := amData["tenantId"]
filterUeIdOnly := bson.M{"ueId": ueId} filterUeIdOnly := bson.M{"ueId": ueId}
authSubsDataInterface, err := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) authSubsDataInterface, err_get := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly)
if err != nil { if err_get != nil {
logger.ProcLog.Errorf("GetSubscribers err: %+v", err) logger.ProcLog.Errorf("GetSubscribers err: %+v", err_get)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var authSubsData AuthSub var authSubsData AuthSub
err = json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData) if err = json.Unmarshal(mapToByte(authSubsDataInterface), &authSubsData); err != nil {
if err != nil {
logger.ProcLog.Errorf("GetSubscribers err: %+v", err) logger.ProcLog.Errorf("GetSubscribers err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
...@@ -1140,55 +1139,55 @@ func GetSubscriberByID(c *gin.Context) { ...@@ -1140,55 +1139,55 @@ func GetSubscriberByID(c *gin.Context) {
} }
var authSubsData models.AuthenticationSubscription 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var amDataData models.AccessAndMobilitySubscriptionData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var smDataData []models.SessionManagementSubscriptionData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var smfSelData models.SmfSelectionSubscriptionData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var amPolicyData models.AmPolicyData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var smPolicyData models.SmPolicyData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var flowRules []FlowRule 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var qosFlows []QosFlow 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
var chargingDatas []ChargingData 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) logger.ProcLog.Errorf("GetSubscriberByID err: %+v", err)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
...@@ -1327,9 +1326,9 @@ func PostSubscriberByID(c *gin.Context) { ...@@ -1327,9 +1326,9 @@ func PostSubscriberByID(c *gin.Context) {
// Lookup same UE ID of other tenant's subscription. // Lookup same UE ID of other tenant's subscription.
if claims != nil { if claims != nil {
authSubsDataInterface, err := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly) authSubsDataInterface, err_get := mongoapi.RestfulAPIGetOne(authSubsDataColl, filterUeIdOnly)
if err != nil { if err_get != nil {
logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_get)
c.JSON(http.StatusInternalServerError, gin.H{}) c.JSON(http.StatusInternalServerError, gin.H{})
return return
} }
...@@ -1536,7 +1535,7 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub ...@@ -1536,7 +1535,7 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub
chargingDataBsonM := toBsonM(chargingData) chargingDataBsonM := toBsonM(chargingData)
// Clear quota for offline charging flow // Clear quota for offline charging flow
if chargingData.ChargingMethod == "Offline" { if chargingData.ChargingMethod == ChargingOffline {
chargingDataBsonM["quota"] = "0" chargingDataBsonM["quota"] = "0"
} }
...@@ -1583,8 +1582,8 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub ...@@ -1583,8 +1582,8 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub
chargingDataBsonM["ueId"] = ueId chargingDataBsonM["ueId"] = ueId
chargingDataBsonM["servingPlmnId"] = servingPlmnId chargingDataBsonM["servingPlmnId"] = servingPlmnId
if _, err := mongoapi.RestfulAPIPutOne(chargingDataColl, chargingFilter, chargingDataBsonM); err != nil { if _, err_put := mongoapi.RestfulAPIPutOne(chargingDataColl, chargingFilter, chargingDataBsonM); err != nil {
logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err) logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err_put)
} }
} }
} }
...@@ -1728,16 +1727,16 @@ func PatchSubscriberByID(c *gin.Context) { ...@@ -1728,16 +1727,16 @@ func PatchSubscriberByID(c *gin.Context) {
c.JSON(http.StatusNoContent, gin.H{}) c.JSON(http.StatusNoContent, gin.H{})
} }
func removeCdrFile(CdrFilePath string) { func removeCdrFile(cdrFilePath string) {
files, err := filepath.Glob(CdrFilePath + "*.cdr") files, err := filepath.Glob(cdrFilePath + "*.cdr")
if err != nil { 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 { 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) 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) logger.BillingLog.Warnf("Failed to remove CDR file: %s\n", file)
} }
} }
...@@ -1907,16 +1906,16 @@ func ChangePasswordInfo(c *gin.Context) { ...@@ -1907,16 +1906,16 @@ func ChangePasswordInfo(c *gin.Context) {
} }
if newUserData.EncryptedPassword != "" { if newUserData.EncryptedPassword != "" {
hash, err := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) hash, err_gen := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12)
if err != nil { if err_gen != nil {
logger.ProcLog.Errorf("GenerateFromPassword err: %+v", err) logger.ProcLog.Errorf("GenerateFromPassword err: %+v", err_gen)
} }
userData.EncryptedPassword = string(hash) userData.EncryptedPassword = string(hash)
} }
userBsonM := toBsonM(userData) userBsonM := toBsonM(userData)
if _, err := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err != nil { if _, err_put := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err_put != nil {
logger.ProcLog.Errorf("PutUserByID err: %+v", err) logger.ProcLog.Errorf("PutUserByID err: %+v", err_put)
} }
c.JSON(http.StatusOK, userData) c.JSON(http.StatusOK, userData)
......
...@@ -41,18 +41,18 @@ func PullCDRFile(c *ftp.ServerConn, fileName string) ([]byte, error) { ...@@ -41,18 +41,18 @@ func PullCDRFile(c *ftp.ServerConn, fileName string) ([]byte, error) {
} }
defer func() { defer func() {
if err := r.Close(); err != nil { if err = r.Close(); err != nil {
logger.BillingLog.Error(err) logger.BillingLog.Error(err)
} }
}() }()
logger.BillingLog.Info("Pull CDR file success") logger.BillingLog.Info("Pull CDR file success")
if err := c.Quit(); err != nil { if err = c.Quit(); err != nil {
return nil, err return nil, err
} }
cdr, err1 := io.ReadAll(r) cdr, err_read := io.ReadAll(r)
return cdr, err1 return cdr, err_read
} }
...@@ -50,8 +50,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { ...@@ -50,8 +50,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
wg: wg, wg: wg,
} }
if _, err := os.Stat("/tmp/webconsole"); err != nil { if _, err := os.Stat("/tmp/webconsole"); err != nil {
if err := os.Mkdir("/tmp/webconsole", os.ModePerm); err != nil { if err_mk := os.Mkdir("/tmp/webconsole", os.ModePerm); err_mk != nil {
logger.BillingLog.Error(err) logger.BillingLog.Error(err_mk)
} }
} }
...@@ -90,8 +90,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain { ...@@ -90,8 +90,8 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
return nil return nil
} }
if err := os.WriteFile(confFile, file, 0o600); err != nil { //nolint: gomnd if err = os.WriteFile(confFile, file, 0o600); err != nil {
logger.BillingLog.Errorf("Couldn't create conf file %v", confFile) logger.BillingLog.Errorf("Couldn't create conf file %v, err: %+v", confFile, err)
return nil return nil
} }
......
...@@ -75,9 +75,9 @@ func SendNFRegistration() error { ...@@ -75,9 +75,9 @@ func SendNFRegistration() error {
return nil return nil
} }
func RetrySendNFRegistration(MaxRetry int) error { func RetrySendNFRegistration(maxRetry int) error {
retryCount := 0 retryCount := 0
for retryCount < MaxRetry { for retryCount < maxRetry {
err := SendNFRegistration() err := SendNFRegistration()
if err == nil { if err == nil {
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment