Skip to content

Commit

Permalink
refactor packages, update go.mod, and add config validator
Browse files Browse the repository at this point in the history
  • Loading branch information
free5gc-org committed Mar 23, 2022
1 parent 88f28c3 commit 7d14dd7
Show file tree
Hide file tree
Showing 74 changed files with 1,161 additions and 728 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.
89 changes: 89 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"fmt"
"math/rand"
"os"
"path/filepath"
"runtime/debug"
"time"

"github.com/asaskevich/govalidator"
"github.com/urfave/cli"

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

var SMF = &service.SMF{}

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 = "smf"
app.Usage = "5G Session Management Function (SMF)"
app.Action = action
app.Flags = SMF.GetCliCmd()
rand.Seed(time.Now().UnixNano())

if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("SMF 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 := SMF.Initialize(c); err != nil {
switch errType := err.(type) {
case govalidator.Errors:
validErrs := err.(govalidator.Errors).Errors()
for _, validErr := range validErrs {
logger.CfgLog.Errorf("%+v", validErr)
}
default:
logger.CfgLog.Errorf("%+v", errType)
}
logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]")
return fmt.Errorf("Failed to initialize !!")
}

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

SMF.Start()

return nil
}

func initLogFile(logNfPath, log5gcPath string) error {
SMF.KeyLogPath = util.SmfDefaultKeyLogPath

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.SmfDefaultKeyLogPath)
SMF.KeyLogPath = filepath.Join(tmpDir, name)
}

return nil
}
208 changes: 0 additions & 208 deletions factory/config.go

This file was deleted.

Loading

0 comments on commit 7d14dd7

Please sign in to comment.