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 b2dcd71 commit 114bd26
Show file tree
Hide file tree
Showing 30 changed files with 762 additions and 578 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.
53 changes: 0 additions & 53 deletions ausf.go

This file was deleted.

93 changes: 93 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
*
* AUSF Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package main

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

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

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

var AUSF = &service.AUSF{}

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 = "ausf"
app.Usage = "5G Authentication Server Function (AUSF)"
app.Action = action
app.Flags = AUSF.GetCliCmd()
if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("AUSF 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 := AUSF.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("AUSF version: ", version.GetVersion())

AUSF.Start()

return nil
}

func initLogFile(logNfPath, log5gcPath string) error {
AUSF.KeyLogPath = util.AusfDefaultKeyLogPath

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

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

This file was deleted.

22 changes: 8 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ go 1.14

require (
github.com/antihax/optional v1.0.0
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/bronze1man/radius v0.0.0-20190516032554-afd8baec892d
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/free5gc/UeauCommon 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/free5gc/openapi v1.0.4
github.com/free5gc/util v1.0.1
github.com/gin-gonic/gin v1.7.3
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.1.2
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/google/uuid v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.5
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit 114bd26

Please sign in to comment.