Skip to content

Commit

Permalink
Enable GCI and GOFUMPT linters and disabled inactive linters (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo authored May 6, 2024
1 parent 77c807c commit 1d52bc2
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 68 deletions.
12 changes: 6 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 free5GC.org
#
# SPDX-License-Identifier: Apache-2.0
#
#

# This file contains all available configuration options
# with their default values.
Expand Down Expand Up @@ -224,21 +224,21 @@ linters:
# Additional
# - lll
- godox
- gomnd
#- gomnd
- goconst
# - gocognit
# - nestif
- gomodguard
# - gomodguard
- nakedret
# - gci
- gci
- misspell
# - gofumpt
- gofumpt
- whitespace
- unconvert
- predeclared
- noctx
- dogsled
- bodyclose
# - bodyclose
- asciicheck
#- stylecheck
# - unparam
Expand Down
3 changes: 2 additions & 1 deletion consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func BuildNFProfile(context *nssf_context.NSSFContext) (profile models.NfProfile
}

var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.NfProfile) (
prof models.NfProfile, resourceNrfUri string, retrieveNfInstanceId string, err error) {
prof models.NfProfile, resourceNrfUri string, retrieveNfInstanceId string, err error,
) {
configuration := Nnrf_NFManagement.NewConfiguration()
configuration.SetBasePath(nrfUri)
apiClient := Nnrf_NFManagement.NewAPIClient(configuration)
Expand Down
11 changes: 6 additions & 5 deletions consumer/nf_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestBuildNFProfile_EmptyContext(t *testing.T) {
ctx := context.NSSFContext{NfId: "test-id"}

profile, err := consumer.BuildNFProfile(&ctx)

if err != nil {
t.Errorf("Error building NFProfile: %v\n", err)
}
Expand All @@ -31,15 +30,17 @@ func TestBuildNFProfile_EmptyContext(t *testing.T) {
}

func TestBuildNFProfile_InitializedContext(t *testing.T) {
ctx := context.NSSFContext{NfId: "test-id",
ctx := context.NSSFContext{
NfId: "test-id",
SupportedPlmnList: []models.PlmnId{{Mcc: "200", Mnc: "99"}},
RegisterIPv4: "127.0.0.42",
NfService: map[models.ServiceName]models.NfService{models.ServiceName_NNSSF_NSSELECTION: {ServiceInstanceId: "instance-id",
ServiceName: "service-name"}},
NfService: map[models.ServiceName]models.NfService{models.ServiceName_NNSSF_NSSELECTION: {
ServiceInstanceId: "instance-id",
ServiceName: "service-name",
}},
}

profile, err := consumer.BuildNFProfile(&ctx)

if err != nil {
t.Errorf("Error building NFProfile: %v\n", err)
}
Expand Down
4 changes: 2 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"

"github.com/google/uuid"

"github.com/omec-project/nssf/factory"
"github.com/omec-project/nssf/logger"
"github.com/omec-project/openapi/models"
Expand Down Expand Up @@ -99,7 +98,8 @@ func InitNssfContext() {
}

func initNfService(serviceName []models.ServiceName, version string) (
nfService map[models.ServiceName]models.NfService) {
nfService map[models.ServiceName]models.NfService,
) {
versionUri := "v" + strings.Split(version, ".")[0]
nfService = make(map[models.ServiceName]models.NfService)
for idx, name := range serviceName {
Expand Down
3 changes: 1 addition & 2 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
"os"
"sync"

"gopkg.in/yaml.v2"

"github.com/omec-project/config5g/proto/client"
"github.com/omec-project/nssf/logger"
"gopkg.in/yaml.v2"
)

var (
Expand Down
5 changes: 2 additions & 3 deletions nssf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"fmt"
"os"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/omec-project/nssf/logger"
"github.com/omec-project/nssf/service"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

var NSSF = &service.NSSF{}
Expand Down
13 changes: 6 additions & 7 deletions producer/nssaiavailability_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"

jsonpatch "github.com/evanphx/json-patch"

"github.com/omec-project/nssf/factory"
"github.com/omec-project/nssf/logger"
"github.com/omec-project/nssf/plugin"
Expand Down Expand Up @@ -49,7 +48,8 @@ func NSSAIAvailabilityDeleteProcedure(nfId string) *models.ProblemDetails {

// NSSAIAvailability PATCH method
func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDocument, nfId string) (
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails) {
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails,
) {
var (
response *models.AuthorizedNssaiAvailabilityInfo = &models.AuthorizedNssaiAvailabilityInfo{}
problemDetails *models.ProblemDetails
Expand Down Expand Up @@ -157,7 +157,8 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc

// NSSAIAvailability PUT method
func NSSAIAvailabilityPutProcedure(nssaiAvailabilityInfo models.NssaiAvailabilityInfo, nfId string) (
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails) {
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails,
) {
var (
response *models.AuthorizedNssaiAvailabilityInfo = &models.AuthorizedNssaiAvailabilityInfo{}
problemDetails *models.ProblemDetails
Expand All @@ -184,8 +185,7 @@ func NSSAIAvailabilityPutProcedure(nssaiAvailabilityInfo models.NssaiAvailabilit
factory.ConfigLock.Lock()
for i, amfConfig := range factory.NssfConfig.Configuration.AmfList {
if amfConfig.NfId == nfId {
factory.NssfConfig.Configuration.AmfList[i].SupportedNssaiAvailabilityData =
nssaiAvailabilityInfo.SupportedNssaiAvailabilityData
factory.NssfConfig.Configuration.AmfList[i].SupportedNssaiAvailabilityData = nssaiAvailabilityInfo.SupportedNssaiAvailabilityData

hitAmf = true
break
Expand All @@ -210,8 +210,7 @@ func NSSAIAvailabilityPutProcedure(nssaiAvailabilityInfo models.NssaiAvailabilit
for _, s := range nssaiAvailabilityInfo.SupportedNssaiAvailabilityData {
authorizedNssaiAvailabilityData, err := util.AuthorizeOfAmfTaFromConfig(nfId, *s.Tai)
if err == nil {
response.AuthorizedNssaiAvailabilityData =
append(response.AuthorizedNssaiAvailabilityData, authorizedNssaiAvailabilityData)
response.AuthorizedNssaiAvailabilityData = append(response.AuthorizedNssaiAvailabilityData, authorizedNssaiAvailabilityData)
} else {
logger.Nssaiavailability.Warnf(err.Error())
}
Expand Down
3 changes: 2 additions & 1 deletion producer/nssaiavailability_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func getUnusedSubscriptionID() (string, error) {

// NSSAIAvailability subscription POST method
func NSSAIAvailabilityPostProcedure(createData models.NssfEventSubscriptionCreateData) (
*models.NssfEventSubscriptionCreatedData, *models.ProblemDetails) {
*models.NssfEventSubscriptionCreatedData, *models.ProblemDetails,
) {
var (
response *models.NssfEventSubscriptionCreatedData = &models.NssfEventSubscriptionCreatedData{}
problemDetails *models.ProblemDetails
Expand Down
12 changes: 5 additions & 7 deletions producer/nsselection_for_pdu_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func selectNsiInformation(nsiInformationList []models.NsiInformation) models.Nsi
// The function is executed when the IE, `slice-info-for-pdu-session`, is provided in query parameters
func nsselectionForPduSession(param plugin.NsselectionQueryParameter,
authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo,
problemDetails *models.ProblemDetails) int {
problemDetails *models.ProblemDetails,
) int {
var status int
if param.HomePlmnId != nil {
// Check whether UE's Home PLMN is supported when UE is a roamer
if !util.CheckSupportedHplmn(*param.HomePlmnId) {
authorizedNetworkSliceInfo.RejectedNssaiInPlmn =
append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, *param.SliceInfoRequestForPduSession.SNssai)
authorizedNetworkSliceInfo.RejectedNssaiInPlmn = append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, *param.SliceInfoRequestForPduSession.SNssai)

status = http.StatusOK
return status
Expand All @@ -50,8 +50,7 @@ func nsselectionForPduSession(param plugin.NsselectionQueryParameter,
if param.Tai != nil {
// Check whether UE's current TA is supported when UE provides TAI
if !util.CheckSupportedTa(*param.Tai) {
authorizedNetworkSliceInfo.RejectedNssaiInTa =
append(authorizedNetworkSliceInfo.RejectedNssaiInTa, *param.SliceInfoRequestForPduSession.SNssai)
authorizedNetworkSliceInfo.RejectedNssaiInTa = append(authorizedNetworkSliceInfo.RejectedNssaiInTa, *param.SliceInfoRequestForPduSession.SNssai)

status = http.StatusOK
return status
Expand Down Expand Up @@ -116,8 +115,7 @@ func nsselectionForPduSession(param plugin.NsselectionQueryParameter,
if param.Tai != nil && !util.CheckSupportedSnssaiInTa(*param.SliceInfoRequestForPduSession.SNssai, *param.Tai) {
// Requested S-NSSAI does not supported in UE's current TA
// Add it to Rejected NSSAI in TA
authorizedNetworkSliceInfo.RejectedNssaiInTa =
append(authorizedNetworkSliceInfo.RejectedNssaiInTa, *param.SliceInfoRequestForPduSession.SNssai)
authorizedNetworkSliceInfo.RejectedNssaiInTa = append(authorizedNetworkSliceInfo.RejectedNssaiInTa, *param.SliceInfoRequestForPduSession.SNssai)
status = http.StatusOK
return status
}
Expand Down
27 changes: 13 additions & 14 deletions producer/nsselection_for_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (

// Set Allowed NSSAI with Subscribed S-NSSAI(s) which are marked as default S-NSSAI(s)
func useDefaultSubscribedSnssai(
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo) {
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo,
) {
var mappingOfSnssai []models.MappingOfSnssai
if param.HomePlmnId != nil {
// Find mapping of Subscribed S-NSSAI of UE's HPLMN to S-NSSAI in Serving PLMN from NSSF configuration
Expand Down Expand Up @@ -88,7 +89,8 @@ func useDefaultSubscribedSnssai(

// Set Configured NSSAI with S-NSSAI(s) in Requested NSSAI which are marked as Default Configured NSSAI
func useDefaultConfiguredNssai(
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo) {
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo,
) {
for _, requestedSnssai := range param.SliceInfoRequestForRegistration.RequestedNssai {
// Check whether the Default Configured S-NSSAI is standard, which could be commonly decided by all roaming partners
if !util.CheckStandardSnssai(requestedSnssai) {
Expand All @@ -113,7 +115,8 @@ func useDefaultConfiguredNssai(

// Set Configured NSSAI with Subscribed S-NSSAI(s)
func setConfiguredNssai(
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo) {
param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo,
) {
var mappingOfSnssai []models.MappingOfSnssai
if param.HomePlmnId != nil {
// Find mapping of Subscribed S-NSSAI of UE's HPLMN to S-NSSAI in Serving PLMN from NSSF configuration
Expand Down Expand Up @@ -160,13 +163,13 @@ func setConfiguredNssai(
// The function is executed when the IE, `slice-info-request-for-registration`, is provided in query parameters
func nsselectionForRegistration(param plugin.NsselectionQueryParameter,
authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo,
problemDetails *models.ProblemDetails) int {
problemDetails *models.ProblemDetails,
) int {
var status int
if param.HomePlmnId != nil {
// Check whether UE's Home PLMN is supported when UE is a roamer
if !util.CheckSupportedHplmn(*param.HomePlmnId) {
authorizedNetworkSliceInfo.RejectedNssaiInPlmn =
append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, param.SliceInfoRequestForRegistration.RequestedNssai...)
authorizedNetworkSliceInfo.RejectedNssaiInPlmn = append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, param.SliceInfoRequestForRegistration.RequestedNssai...)

status = http.StatusOK
return status
Expand All @@ -176,8 +179,7 @@ func nsselectionForRegistration(param plugin.NsselectionQueryParameter,
if param.Tai != nil {
// Check whether UE's current TA is supported when UE provides TAI
if !util.CheckSupportedTa(*param.Tai) {
authorizedNetworkSliceInfo.RejectedNssaiInTa =
append(authorizedNetworkSliceInfo.RejectedNssaiInTa, param.SliceInfoRequestForRegistration.RequestedNssai...)
authorizedNetworkSliceInfo.RejectedNssaiInTa = append(authorizedNetworkSliceInfo.RejectedNssaiInTa, param.SliceInfoRequestForRegistration.RequestedNssai...)

status = http.StatusOK
return status
Expand All @@ -191,8 +193,7 @@ func nsselectionForRegistration(param plugin.NsselectionQueryParameter,
// for S-NSSAIs in both `sNssaiForMapping` and `subscribedSnssai` if present

if param.HomePlmnId == nil {
problemDetail :=
"[Query Parameter] `home-plmn-id` should be provided when requesting VPLMN specific mapped S-NSSAI values"
problemDetail := "[Query Parameter] `home-plmn-id` should be provided when requesting VPLMN specific mapped S-NSSAI values"
*problemDetails = models.ProblemDetails{
Title: util.INVALID_REQUEST,
Status: http.StatusBadRequest,
Expand Down Expand Up @@ -334,8 +335,7 @@ func nsselectionForRegistration(param plugin.NsselectionQueryParameter,
// TODO: Search for local configuration if there is no provided mapping from UE, and update UE's
// Configured NSSAI
checkInvalidRequestedNssai = true
authorizedNetworkSliceInfo.RejectedNssaiInPlmn =
append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, requestedSnssai)
authorizedNetworkSliceInfo.RejectedNssaiInPlmn = append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, requestedSnssai)
continue
} else {
// TODO: Check if mappings of S-NSSAIs are correct
Expand Down Expand Up @@ -386,8 +386,7 @@ func nsselectionForRegistration(param plugin.NsselectionQueryParameter,
// Requested S-NSSAI does not match any Subscribed S-NSSAI
// Add it to Rejected NSSAI in PLMN
checkInvalidRequestedNssai = true
authorizedNetworkSliceInfo.RejectedNssaiInPlmn =
append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, requestedSnssai)
authorizedNetworkSliceInfo.RejectedNssaiInPlmn = append(authorizedNetworkSliceInfo.RejectedNssaiInPlmn, requestedSnssai)
}
}

Expand Down
2 changes: 1 addition & 1 deletion producer/subscription_id_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package producer

import (
"net/http"
"reflect"

"github.com/omec-project/nssf/logger"
"github.com/omec-project/openapi/models"
"github.com/omec-project/util/httpwrapper"
"reflect"
)

// HandleNSSAIAvailabilityUnsubscribe - Deletes an already existing NSSAI availability notification subscription
Expand Down
20 changes: 10 additions & 10 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"syscall"
"time"

"github.com/omec-project/openapi/models"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/omec-project/http2_util"
"github.com/omec-project/logger_util"
"github.com/omec-project/nssf/consumer"
Expand All @@ -34,8 +30,11 @@ import (
"github.com/omec-project/nssf/nssaiavailability"
"github.com/omec-project/nssf/nsselection"
"github.com/omec-project/nssf/util"
"github.com/omec-project/openapi/models"
"github.com/omec-project/util/path_util"
pathUtilLogger "github.com/omec-project/util/path_util/logger"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

type NSSF struct{}
Expand Down Expand Up @@ -269,7 +268,7 @@ func (nssf *NSSF) StartKeepAliveTimer(nfProfile models.NfProfile) {
nfProfile.HeartBeatTimer = 60
}
logger.InitLog.Infof("Started KeepAlive Timer: %v sec", nfProfile.HeartBeatTimer)
//AfterFunc starts timer and waits for KeepAliveTimer to elapse and then calls nssf.UpdateNF function
// AfterFunc starts timer and waits for KeepAliveTimer to elapse and then calls nssf.UpdateNF function
KeepAliveTimer = time.AfterFunc(time.Duration(nfProfile.HeartBeatTimer)*time.Second, nssf.UpdateNF)
}

Expand All @@ -289,7 +288,7 @@ func (nssf *NSSF) BuildAndSendRegisterNFInstance() (models.NfProfile, error) {
return profile, err
}
initLog.Infof("Pcf Profile Registering to NRF: %v", profile)
//Indefinite attempt to register until success
// Indefinite attempt to register until success
profile, _, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, profile)
return profile, err
}
Expand All @@ -302,7 +301,7 @@ func (nssf *NSSF) UpdateNF() {
initLog.Warnf("KeepAlive timer has been stopped.")
return
}
//setting default value 60 sec
// setting default value 60 sec
var heartBeatTimer int32 = 60
pitem := models.PatchItem{
Op: "replace",
Expand All @@ -314,10 +313,10 @@ func (nssf *NSSF) UpdateNF() {
nfProfile, problemDetails, err := consumer.SendUpdateNFInstance(patchItem)
if problemDetails != nil {
initLog.Errorf("NSSF update to NRF ProblemDetails[%v]", problemDetails)
//5xx response from NRF, 404 Not Found, 400 Bad Request
// 5xx response from NRF, 404 Not Found, 400 Bad Request
if (problemDetails.Status >= 500 && problemDetails.Status <= 599) ||
problemDetails.Status == 404 || problemDetails.Status == 400 {
//register with NRF full profile
// register with NRF full profile
nfProfile, err = nssf.BuildAndSendRegisterNFInstance()
if err != nil {
initLog.Errorf("NSSF update to NRF Error[%s]", err.Error())
Expand All @@ -336,9 +335,10 @@ func (nssf *NSSF) UpdateNF() {
heartBeatTimer = nfProfile.HeartBeatTimer
}
logger.InitLog.Debugf("Restarted KeepAlive Timer: %v sec", heartBeatTimer)
//restart timer with received HeartBeatTimer value
// restart timer with received HeartBeatTimer value
KeepAliveTimer = time.AfterFunc(time.Duration(heartBeatTimer)*time.Second, nssf.UpdateNF)
}

func (nssf *NSSF) registerNF() {
for msg := range factory.ConfigPodTrigger {
initLog.Infof("Minimum configuration from config pod available %v", msg)
Expand Down
Loading

0 comments on commit 1d52bc2

Please sign in to comment.