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 e74af1f commit f159dc9
Show file tree
Hide file tree
Showing 39 changed files with 1,051 additions and 970 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.
73 changes: 0 additions & 73 deletions accesstoken/api_access_token_request_test.go

This file was deleted.

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

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

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

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

var NRF = &nrf_service.NRF{}

func main() {
app := cli.NewApp()
app.Name = "nrf"
app.Usage = "5G Network Repository Function (NRF)"
app.Action = action
app.Flags = NRF.GetCliCmd()
if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("NRF 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 := NRF.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("NRF version: ", version.GetVersion())

NRF.Start()

return nil
}

func initLogFile(logNfPath, log5gcPath string) error {
NRF.KeyLogPath = util.NrfDefaultKeyLogPath

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

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

This file was deleted.

28 changes: 10 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ go 1.14

require (
github.com/antihax/optional v1.0.0
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/free5gc/MongoDBLibrary v1.0.0
github.com/free5gc/TimeDecode v1.0.0
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/mitchellh/mapstructure v1.4.0
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/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/free5gc/openapi v1.0.4
github.com/free5gc/util v1.0.1
github.com/gin-gonic/gin v1.7.3
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/google/uuid v1.3.0
github.com/mitchellh/mapstructure v1.4.1
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli v1.22.5
go.mongodb.org/mongo-driver v1.4.4
go.mongodb.org/mongo-driver v1.7.1
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit f159dc9

Please sign in to comment.