Skip to content

Commit 9fc9f68

Browse files
committed
refactor packages, update go.mod, and add config validator
1 parent 816b57d commit 9fc9f68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+765
-569
lines changed

.gitignore

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
# Swap files
2+
*.swp
3+
14
# Toolchain
2-
# Goland project folder
5+
# Golang project folder
36
.idea/
7+
48
# Visual Studio Code
59
.vscode/
10+
11+
# Build
12+
build/
13+
log/
14+
vendor/
15+
616
# emacs/vim
717
GPATH
818
GRTAGS
919
GTAGS
1020
TAGS
1121
tags
1222
cscope.*
13-
# mac
23+
24+
# macOS
1425
.DS_Store
1526

16-
# debug
27+
# Debug
1728
*.log
1829
*.pcap
19-

.golangci.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ run:
2929
# "/" will be replaced by current OS file path separator to properly work
3030
# on Windows.
3131
skip-files:
32-
- "api_.*\\.go$"
33-
- "model_.*\\.go$"
34-
- "routers.go"
35-
- "client.go"
36-
- "configuration.go"
37-
- "nas.go"
3832
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
3933
# If invoked with -mod=readonly, the go command is disallowed from the implicit
4034
# automatic updating of go.mod described above. Instead, it fails when any changes
@@ -250,13 +244,14 @@ linters:
250244
# Additional
251245
- lll
252246
- godox
253-
#- gomnd
254-
#- goconst
247+
# - gomnd
248+
# - goconst
255249
# - gocognit
256250
# - maligned
257251
# - nestif
258252
# - gomodguard
259253
- nakedret
254+
# - golint
260255
- gci
261256
- misspell
262257
- gofumpt
@@ -267,9 +262,9 @@ linters:
267262
- dogsled
268263
- bodyclose
269264
- asciicheck
270-
#- stylecheck
271-
# - unparam
272-
# - wsl
265+
# - stylecheck
266+
# - unparam
267+
# - wsl
273268

274269
#disable-all: false
275270
fast: true

CHANGELOG.md

-9
This file was deleted.

LICENSE.txt LICENSE

File renamed without changes.

cmd/main.go

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Npcf_BDTPolicyControl Service API
3+
*
4+
* The Npcf_BDTPolicyControl Service is used by an NF service consumer to
5+
* retrieve background data transfer policies from the PCF and to update the PCF with
6+
* the background data transfer policy selected by the NF service consumer.
7+
*
8+
* API version: 1.0.0
9+
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
10+
*/
11+
12+
package main
13+
14+
import (
15+
"fmt"
16+
"os"
17+
"path/filepath"
18+
"runtime/debug"
19+
20+
"github.com/asaskevich/govalidator"
21+
"github.com/urfave/cli"
22+
23+
"github.com/free5gc/pcf/internal/logger"
24+
"github.com/free5gc/pcf/internal/util"
25+
"github.com/free5gc/pcf/pkg/service"
26+
"github.com/free5gc/util/version"
27+
)
28+
29+
var PCF = &service.PCF{}
30+
31+
func main() {
32+
defer func() {
33+
if p := recover(); p != nil {
34+
// Print stack for panic to log. Fatalf() will let program exit.
35+
logger.AppLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))
36+
}
37+
}()
38+
39+
app := cli.NewApp()
40+
app.Name = "pcf"
41+
app.Usage = "5G Policy Control Function (PCF)"
42+
app.Action = action
43+
app.Flags = PCF.GetCliCmd()
44+
if err := app.Run(os.Args); err != nil {
45+
fmt.Printf("PCF Run Error: %v\n", err)
46+
}
47+
}
48+
49+
func action(c *cli.Context) error {
50+
if err := initLogFile(c.String("log"), c.String("log5gc")); err != nil {
51+
logger.AppLog.Errorf("%+v", err)
52+
return err
53+
}
54+
55+
if err := PCF.Initialize(c); err != nil {
56+
switch err1 := err.(type) {
57+
case govalidator.Errors:
58+
errs := err1.Errors()
59+
for _, e := range errs {
60+
logger.CfgLog.Errorf("%+v", e)
61+
}
62+
default:
63+
logger.CfgLog.Errorf("%+v", err)
64+
}
65+
66+
logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]")
67+
return fmt.Errorf("Failed to initialize !!")
68+
}
69+
logger.AppLog.Infoln(c.App.Name)
70+
logger.AppLog.Infoln("PCF version: ", version.GetVersion())
71+
72+
PCF.Start()
73+
74+
return nil
75+
}
76+
77+
func initLogFile(logNfPath, log5gcPath string) error {
78+
PCF.KeyLogPath = util.PcfDefaultKeyLogPath
79+
80+
if err := logger.LogFileHook(logNfPath, log5gcPath); err != nil {
81+
return err
82+
}
83+
84+
if logNfPath != "" {
85+
nfDir, _ := filepath.Split(logNfPath)
86+
tmpDir := filepath.Join(nfDir, "key")
87+
if err := os.MkdirAll(tmpDir, 0775); err != nil {
88+
logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)
89+
return err
90+
}
91+
_, name := filepath.Split(util.PcfDefaultKeyLogPath)
92+
PCF.KeyLogPath = filepath.Join(tmpDir, name)
93+
}
94+
95+
return nil
96+
}

factory/config.go

-66
This file was deleted.

go.mod

+8-16
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,18 @@ go 1.14
44

55
require (
66
github.com/antihax/optional v1.0.0
7-
github.com/antonfisher/nested-logrus-formatter v1.3.0
8-
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
7+
github.com/antonfisher/nested-logrus-formatter v1.3.1
8+
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
99
github.com/cydev/zero v0.0.0-20160322155811-4a4535dd56e7
10-
github.com/free5gc/MongoDBLibrary v1.0.0
11-
github.com/free5gc/http2_util v1.0.0
12-
github.com/free5gc/http_wrapper v1.0.0
13-
github.com/free5gc/idgenerator v1.0.0
14-
github.com/free5gc/logger_conf v1.0.0
15-
github.com/free5gc/logger_util v1.0.0
16-
github.com/free5gc/openapi v1.0.0
17-
github.com/free5gc/path_util v1.0.0
18-
github.com/free5gc/version v1.0.0
10+
github.com/free5gc/openapi v1.0.4
11+
github.com/free5gc/util v1.0.1
1912
github.com/gin-contrib/cors v1.3.1
20-
github.com/gin-gonic/gin v1.6.3
21-
github.com/google/uuid v1.1.2
13+
github.com/gin-gonic/gin v1.7.3
14+
github.com/google/uuid v1.3.0
2215
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
23-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
24-
github.com/sirupsen/logrus v1.7.0
16+
github.com/sirupsen/logrus v1.8.1
2517
github.com/tim-ywliu/event v0.1.0
2618
github.com/urfave/cli v1.22.5
27-
go.mongodb.org/mongo-driver v1.4.4
19+
go.mongodb.org/mongo-driver v1.7.1
2820
gopkg.in/yaml.v2 v2.4.0
2921
)

0 commit comments

Comments
 (0)