Skip to content

Commit

Permalink
refactor packages and update go.mod
Browse files Browse the repository at this point in the history
  • Loading branch information
free5gc-org committed Mar 23, 2022
1 parent 399df69 commit e9e9138
Show file tree
Hide file tree
Showing 34 changed files with 422 additions and 768 deletions.
18 changes: 14 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# Swap files
*.swp

# Toolchain
# Goland project folder
# Golang project folder
.idea/

# Visual Studio Code
.vscode/

# Build
build/
log/
vendor/

# emacs/vim
GPATH
GRTAGS
GTAGS
TAGS
tags
cscope.*
# mac

# macOS
.DS_Store

# debug
# Debug
*.log
*.pcap

17 changes: 6 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ run:
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- "api_.*\\.go$"
- "model_.*\\.go$"
- "routers.go"
- "client.go"
- "configuration.go"
- "nas.go"
# 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
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand Down Expand Up @@ -249,13 +243,14 @@ linters:
# Additional
- lll
- godox
#- gomnd
#- goconst
# - gomnd
# - goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
# - golint
- gci
- misspell
- gofumpt
Expand All @@ -266,9 +261,9 @@ linters:
- dogsled
- bodyclose
- asciicheck
#- stylecheck
# - unparam
# - wsl
# - stylecheck
# - unparam
# - wsl

#disable-all: false
fast: true
Expand Down
9 changes: 0 additions & 9 deletions CHANGELOG.md

This file was deleted.

File renamed without changes.
75 changes: 75 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"fmt"
"os"
"path/filepath"
"runtime/debug"

"github.com/urfave/cli"

"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/util"
"github.com/free5gc/nssf/pkg/service"
"github.com/free5gc/util/version"
)

var NSSF = &service.NSSF{}

func main() {
defer func() {
if p := recover(); p != nil {
// Print stack for panic to log. Fatalf() will let program exit.
logger.AppLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))
}
}()

app := cli.NewApp()
app.Name = "nssf"
app.Usage = "5G Network Slice Selection Function (NSSF)"
app.Action = action
app.Flags = NSSF.GetCliCmd()
if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("NSSF Run Error: %v\n", err)
}
}

func action(c *cli.Context) error {
if err := initLogFile(c.String("log"), c.String("log5gc")); err != nil {
logger.AppLog.Errorf("%+v", err)
return err
}

if err := NSSF.Initialize(c); err != nil {
logger.CfgLog.Errorf("%+v", err)
return fmt.Errorf("Failed to initialize !!")
}

logger.AppLog.Infoln(c.App.Name)
logger.AppLog.Infoln("NSSF version: ", version.GetVersion())

NSSF.Start()

return nil
}

func initLogFile(logNfPath, log5gcPath string) error {
NSSF.KeyLogPath = util.NssfDefaultKeyLogPath

if err := logger.LogFileHook(logNfPath, log5gcPath); err != nil {
return err
}

if logNfPath != "" {
nfDir, _ := filepath.Split(logNfPath)
tmpDir := filepath.Join(nfDir, "key")
if err := os.MkdirAll(tmpDir, 0775); err != nil {
logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)
return err
}
_, name := filepath.Split(util.NssfDefaultKeyLogPath)
NSSF.KeyLogPath = filepath.Join(tmpDir, name)
}

return nil
}
22 changes: 7 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ module github.com/free5gc/nssf
go 1.14

require (
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/free5gc/http2_util v1.0.0
github.com/free5gc/http_wrapper v1.0.0
github.com/free5gc/logger_conf v1.0.0
github.com/free5gc/logger_util v1.0.0
github.com/free5gc/openapi v1.0.0
github.com/free5gc/path_util v1.0.0
github.com/free5gc/version v1.0.0
github.com/gin-gonic/gin v1.6.3
github.com/google/uuid v1.1.2
github.com/leodido/go-urn v1.2.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/evanphx/json-patch v0.5.2
github.com/free5gc/openapi v1.0.4
github.com/free5gc/util v1.0.1
github.com/gin-gonic/gin v1.7.3
github.com/google/uuid v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli v1.22.5
gopkg.in/yaml.v2 v2.4.0
)
184 changes: 114 additions & 70 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions context/context.go → internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/google/uuid"

"github.com/free5gc/nssf/factory"
"github.com/free5gc/nssf/logger"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/pkg/factory"
"github.com/free5gc/openapi/models"
)

Expand Down
43 changes: 29 additions & 14 deletions logger/logger.go → internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
formatter "github.com/antonfisher/nested-logrus-formatter"
"github.com/sirupsen/logrus"

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

var (
Expand Down Expand Up @@ -38,16 +37,6 @@ func init() {
FieldsOrder: []string{"component", "category"},
}

free5gcLogHook, err := logger_util.NewFileHook(logger_conf.Free5gcLogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666)
if err == nil {
log.Hooks.Add(free5gcLogHook)
}

selfLogHook, err := logger_util.NewFileHook(logger_conf.NfLogDir+"nssf.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666)
if err == nil {
log.Hooks.Add(selfLogHook)
}

AppLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "App"})
ContextLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "CTX"})
FactoryLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "Factory"})
Expand All @@ -61,10 +50,36 @@ func init() {
GinLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "GIN"})
}

func LogFileHook(logNfPath string, log5gcPath string) error {
if fullPath, err := logger_util.CreateFree5gcLogFile(log5gcPath); err == nil {
if fullPath != "" {
free5gcLogHook, hookErr := logger_util.NewFileHook(fullPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666)
if hookErr != nil {
return hookErr
}
log.Hooks.Add(free5gcLogHook)
}
} else {
return err
}

if fullPath, err := logger_util.CreateNfLogFile(logNfPath, "nssf.log"); err == nil {
selfLogHook, hookErr := logger_util.NewFileHook(fullPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666)
if hookErr != nil {
return hookErr
}
log.Hooks.Add(selfLogHook)
} else {
return err
}

return nil
}

func SetLogLevel(level logrus.Level) {
log.SetLevel(level)
}

func SetReportCaller(set bool) {
log.SetReportCaller(set)
func SetReportCaller(enable bool) {
log.SetReportCaller(enable)
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"time"

nssf_context "github.com/free5gc/nssf/context"
"github.com/free5gc/nssf/logger"
nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Nnrf_NFManagement"
"github.com/free5gc/openapi/models"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (

"github.com/gin-gonic/gin"

"github.com/free5gc/http_wrapper"
"github.com/free5gc/nssf/logger"
"github.com/free5gc/nssf/plugin"
"github.com/free5gc/nssf/producer"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/plugin"
"github.com/free5gc/nssf/internal/sbi/producer"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
)

func HTTPNSSAIAvailabilityDelete(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["nfId"] = c.Params.ByName("nfId")

rsp := producer.HandleNSSAIAvailabilityDelete(req)
Expand Down Expand Up @@ -71,7 +71,7 @@ func HTTPNSSAIAvailabilityPatch(c *gin.Context) {
return
}

req := http_wrapper.NewRequest(c.Request, nssaiAvailabilityUpdateInfo)
req := httpwrapper.NewRequest(c.Request, nssaiAvailabilityUpdateInfo)
req.Params["nfId"] = c.Params.ByName("nfId")

rsp := producer.HandleNSSAIAvailabilityPatch(req)
Expand Down Expand Up @@ -119,7 +119,7 @@ func HTTPNSSAIAvailabilityPut(c *gin.Context) {
return
}

req := http_wrapper.NewRequest(c.Request, nssaiAvailabilityInfo)
req := httpwrapper.NewRequest(c.Request, nssaiAvailabilityInfo)
req.Params["nfId"] = c.Params.ByName("nfId")

rsp := producer.HandleNSSAIAvailabilityPut(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

"github.com/gin-gonic/gin"

"github.com/free5gc/http_wrapper"
"github.com/free5gc/nssf/logger"
"github.com/free5gc/nssf/producer"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/sbi/producer"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
)

func HTTPNSSAIAvailabilityUnsubscribe(c *gin.Context) {
Expand All @@ -30,7 +30,7 @@ func HTTPNSSAIAvailabilityUnsubscribe(c *gin.Context) {
return
}

req := http_wrapper.NewRequest(c.Request, nil)
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["subscriptionId"] = c.Params.ByName("subscriptionId")

rsp := producer.HandleNSSAIAvailabilityUnsubscribe(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (

"github.com/gin-gonic/gin"

"github.com/free5gc/http_wrapper"
"github.com/free5gc/nssf/logger"
"github.com/free5gc/nssf/producer"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/sbi/producer"
"github.com/free5gc/openapi"
. "github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
)

func HTTPNSSAIAvailabilityPost(c *gin.Context) {
Expand Down Expand Up @@ -50,7 +50,7 @@ func HTTPNSSAIAvailabilityPost(c *gin.Context) {
return
}

req := http_wrapper.NewRequest(c.Request, createData)
req := httpwrapper.NewRequest(c.Request, createData)

rsp := producer.HandleNSSAIAvailabilityPost(req)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/gin-gonic/gin"

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

// Route is the information for every URI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (

"github.com/gin-gonic/gin"

"github.com/free5gc/http_wrapper"
"github.com/free5gc/nssf/logger"
"github.com/free5gc/nssf/producer"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/sbi/producer"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/httpwrapper"
)

func HTTPNetworkSliceInformationDocument(c *gin.Context) {
req := http_wrapper.NewRequest(c.Request, nil)
req := httpwrapper.NewRequest(c.Request, nil)

rsp := producer.HandleNSSelectionGet(req)

Expand Down
Loading

0 comments on commit e9e9138

Please sign in to comment.