Skip to content

Commit

Permalink
fix: golangci-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchennn committed Aug 29, 2023
1 parent 5aa5625 commit 2798a88
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ linters-settings:
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
line-length: 150
# tab width in spaces. Default to 1.
tab-width: 1
maligned:
Expand Down
75 changes: 54 additions & 21 deletions backend/WebUI/api_webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ import (
"strings"
"time"

"github.com/free5gc/chf/cdr/asn"
"github.com/free5gc/chf/cdr/cdrFile"
"github.com/free5gc/chf/cdr/cdrType"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/mongoapi"
"github.com/free5gc/webconsole/backend/logger"
"github.com/free5gc/webconsole/backend/webui_context"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"golang.org/x/crypto/bcrypt"

"github.com/free5gc/chf/cdr/asn"
"github.com/free5gc/chf/cdr/cdrFile"
"github.com/free5gc/chf/cdr/cdrType"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/mongoapi"
"github.com/free5gc/webconsole/backend/logger"
"github.com/free5gc/webconsole/backend/webui_context"
)

const (
Expand Down Expand Up @@ -1392,15 +1393,23 @@ func sendRechargeNotification(ueId string, rg int32) {
webuiSelf.UpdateNfProfiles()

requestUri := fmt.Sprintf("%s/nchf-convergedcharging/v3/recharging/%s_%d", "http://127.0.0.113:8000", ueId, rg)
req, err := http.NewRequest(http.MethodPut, requestUri, nil)

req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, requestUri, nil)
if err != nil {
logger.ProcLog.Error(err)
}

req.Header.Add("Content-Type", "application/json")

if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
logger.ProcLog.Errorf("Send Charging Notification err: %+v", err)
}
defer func() {
if closeErr := resp.Body.Close(); closeErr != nil {
logger.ProcLog.Error(closeErr)
}
}()
}

func dbOperation(ueId string, servingPlmnId string, method string, subsData *SubsData, claims jwt.MapClaims) {
Expand Down Expand Up @@ -1539,11 +1548,15 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub
}

if chargingData.Dnn != "" && chargingData.Filter != "" {
chargingFilter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId,
"snssai": chargingData.Snssai, "dnn": chargingData.Dnn, "filter": chargingData.Filter}
chargingFilter = bson.M{
"ueId": ueId, "servingPlmnId": servingPlmnId,
"snssai": chargingData.Snssai, "dnn": chargingData.Dnn, "filter": chargingData.Filter,
}
} else {
chargingFilter = bson.M{"ueId": ueId, "servingPlmnId": servingPlmnId,
"snssai": chargingData.Snssai, "dnn": "", "filter": ""}
chargingFilter = bson.M{
"ueId": ueId, "servingPlmnId": servingPlmnId,
"snssai": chargingData.Snssai, "dnn": "", "filter": "",
}
chargingDataBsonM["dnn"] = ""
chargingDataBsonM["filter"] = ""
}
Expand All @@ -1552,8 +1565,10 @@ func dbOperation(ueId string, servingPlmnId string, method string, subsData *Sub
if err != nil {
logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err)
}
json.Unmarshal(mapToByte(previousChargingDataInterface), &previousChargingData)

err = json.Unmarshal(mapToByte(previousChargingDataInterface), &previousChargingData)
if err != nil {
logger.ProcLog.Error(err)
}
ratingGroup := previousChargingDataInterface["ratingGroup"]
if ratingGroup != nil {
rg := ratingGroup.(int32)
Expand Down Expand Up @@ -1917,8 +1932,10 @@ func parseCDR(supi string) map[int64]RatingGroupDataUsage {
for _, cdr := range newCdrFile.CdrList {
recvByte := cdr.CdrByte
val := reflect.New(reflect.TypeOf(&cdrType.ChargingRecord{}).Elem()).Interface()
asn.UnmarshalWithParams(recvByte, val, "")

err := asn.UnmarshalWithParams(recvByte, val, "")
if err != nil {
logger.BillingLog.Error(err)
}
chargingRecord := *(val.(*cdrType.ChargingRecord))

for _, multipleUnitUsage := range chargingRecord.ListOfMultipleUnitUsage {
Expand Down Expand Up @@ -1954,14 +1971,23 @@ func GetChargingRecord(c *gin.Context) {
if amfUris := webuiSelf.GetOamUris(models.NfType_AMF); amfUris != nil {
requestUri := fmt.Sprintf("%s/namf-oam/v1/registered-ue-context", amfUris[0])

resp, err := httpsClient.Get(requestUri)
resp, err := http.NewRequestWithContext(context.Background(), http.MethodGet, requestUri, nil)
if err != nil {
logger.ProcLog.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{})
return
}

json.NewDecoder(resp.Body).Decode(&uesJsonData)
defer func() {
if closeErr := resp.Body.Close(); closeErr != nil {
logger.ProcLog.Error(closeErr)
}
}()

err = json.NewDecoder(resp.Body).Decode(&uesJsonData)
if err != nil {
logger.BillingLog.Error(err)
}
}

// build charging records
Expand All @@ -1986,8 +2012,15 @@ func GetChargingRecord(c *gin.Context) {
logger.ProcLog.Errorf("PostSubscriberByID err: %+v", err)
}

json.Unmarshal(mapToByte(chargingDataInterface), &chargingData)
quota, _ := strconv.ParseInt(chargingData.Quota, 10, 64)
err = json.Unmarshal(mapToByte(chargingDataInterface), &chargingData)
if err != nil {
logger.BillingLog.Error(err)
}

quota, err := strconv.ParseInt(chargingData.Quota, 10, 64)
if err != nil {
logger.BillingLog.Error(err)
}

if chargingData.Filter != "" && chargingData.Dnn != "" {
flowInfos = append(flowInfos, FlowInfo{
Expand Down
9 changes: 7 additions & 2 deletions backend/billing/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strconv"
"time"

"github.com/jlaffaye/ftp"

"github.com/free5gc/webconsole/backend/factory"
"github.com/free5gc/webconsole/backend/logger"
"github.com/jlaffaye/ftp"
)

// The ftp client is for CDR Pull method, that is the billing domain actively query CDR file from CHF
Expand Down Expand Up @@ -39,7 +40,11 @@ func PullCDRFile(c *ftp.ServerConn, fileName string) ([]byte, error) {
return nil, err
}

defer r.Close()
defer func() {
if err := r.Close(); err != nil {
logger.BillingLog.Error(err)
}
}()

logger.BillingLog.Info("Pull CDR file success")

Expand Down
7 changes: 5 additions & 2 deletions backend/billing/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/fclairamb/ftpserver/config"
"github.com/fclairamb/ftpserver/server"
ftpserver "github.com/fclairamb/ftpserverlib"

"github.com/free5gc/webconsole/backend/factory"
"github.com/free5gc/webconsole/backend/logger"
)
Expand Down Expand Up @@ -41,7 +42,9 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {

b := &BillingDomain{}
if _, err := os.Stat("/tmp/webconsole"); err != nil {
os.Mkdir("/tmp/webconsole", os.ModePerm)
if err := os.Mkdir("/tmp/webconsole", os.ModePerm); err != nil {
logger.BillingLog.Error(err)
}
}

billingConfig := factory.WebuiConfig.Configuration.BillingServer
Expand Down Expand Up @@ -76,7 +79,7 @@ func OpenServer(wg *sync.WaitGroup) *BillingDomain {
return nil
}

if err := ioutil.WriteFile(confFile, file, 0600); err != nil { //nolint: gomnd
if err := ioutil.WriteFile(confFile, file, 0o600); err != nil { //nolint: gomnd
logger.BillingLog.Errorf("Couldn't create conf file %v", confFile)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion backend/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package logger
import (
golog "github.com/fclairamb/go-log"
adapter "github.com/fclairamb/go-log/logrus"
logger_util "github.com/free5gc/util/logger"
"github.com/sirupsen/logrus"

logger_util "github.com/free5gc/util/logger"
)

var (
Expand Down

0 comments on commit 2798a88

Please sign in to comment.