|
1 | 1 | package config
|
2 | 2 |
|
3 |
| -import ( |
4 |
| - log "github.com/sirupsen/logrus" |
5 |
| - "gopkg.in/yaml.v2" |
6 |
| - "io/ioutil" |
7 |
| - "path" |
8 |
| - "path/filepath" |
9 |
| - "runtime" |
10 |
| -) |
11 |
| - |
12 |
| -// Conf: Used for access to configuration |
13 |
| -var Data = getConfig() |
14 |
| - |
15 | 3 | type Config struct {
|
16 | 4 | GNodeB struct {
|
17 | 5 | ControlIF struct {
|
18 |
| - Ip string `yaml: "ip"` |
19 |
| - Port int `yaml: "port"` |
20 |
| - } `yaml: "controlif"` |
| 6 | + Ip string `yaml:"ip"` |
| 7 | + Port int `yaml:"port"` |
| 8 | + } `yaml:"controlif"` |
21 | 9 | DataIF struct {
|
22 |
| - Ip string `yaml: "ip"` |
23 |
| - Port int `yaml: "port"` |
24 |
| - } `yaml: "dataif"` |
| 10 | + Ip string `yaml:"ip"` |
| 11 | + Port int `yaml:"port"` |
| 12 | + } `yaml:"dataif"` |
25 | 13 | PlmnList struct {
|
26 |
| - Mcc string `yaml: "mmc"` |
27 |
| - Mnc string `yaml: "mnc"` |
28 |
| - Tac string `yaml: "tac"` |
29 |
| - GnbId string `yaml: "gnbid"` |
30 |
| - } `yaml: "plmnlist"` |
| 14 | + Mcc string `yaml:"mmc"` |
| 15 | + Mnc string `yaml:"mnc"` |
| 16 | + Tac string `yaml:"tac"` |
| 17 | + GnbId string `yaml:"gnbid"` |
| 18 | + } `yaml:"plmnlist"` |
31 | 19 | SliceSupportList struct {
|
32 |
| - Sst string `yaml: "sst"` |
33 |
| - Sd string `yaml: "sd"` |
34 |
| - } `yaml: "slicesupportlist"` |
| 20 | + Sst string `yaml:"sst"` |
| 21 | + Sd string `yaml:"sd"` |
| 22 | + } `yaml:"slicesupportlist"` |
35 | 23 | } `yaml:"gnodeb"`
|
36 | 24 | Ue struct {
|
37 |
| - Msin string `yaml: "msin"` |
38 |
| - Key string `yaml: "key"` |
39 |
| - Opc string `yaml: "opc"` |
40 |
| - Amf string `yaml: "amf"` |
41 |
| - Sqn string `yaml: "sqn"` |
| 25 | + Msin string `yaml:"msin"` |
| 26 | + Key string `yaml:"key"` |
| 27 | + Opc string `yaml:"opc"` |
| 28 | + Amf string `yaml:"amf"` |
| 29 | + Sqn string `yaml:"sqn"` |
42 | 30 | Hplmn struct {
|
43 |
| - Mcc string `yaml: "mcc"` |
44 |
| - Mnc string `yaml: "mnc"` |
45 |
| - } `yaml: "hplmn"` |
| 31 | + Mcc string `yaml:"mcc"` |
| 32 | + Mnc string `yaml:"mnc"` |
| 33 | + } `yaml:"hplmn"` |
46 | 34 | Snssai struct {
|
47 |
| - Sst int `yaml: "sst"` |
48 |
| - Sd string `yaml: "sd"` |
49 |
| - } `yaml: "snssai"` |
| 35 | + Sst int `yaml:"sst"` |
| 36 | + Sd string `yaml:"sd"` |
| 37 | + } `yaml:"snssai"` |
50 | 38 | } `yaml:"ue"`
|
51 | 39 | AMF struct {
|
52 |
| - Ip string `yaml: "ip"` |
53 |
| - Port int `yaml: "port"` |
54 |
| - Name string `yaml: "name"` |
| 40 | + Ip string `yaml:"ip"` |
| 41 | + Port int `yaml:"port"` |
| 42 | + Name string `yaml:"name"` |
55 | 43 | } `yaml:"amfif"`
|
56 | 44 | }
|
57 |
| - |
58 |
| -func RootDir() string { |
59 |
| - _, b, _, _ := runtime.Caller(0) |
60 |
| - d := path.Join(path.Dir(b)) |
61 |
| - return filepath.Dir(d) |
62 |
| -} |
63 |
| - |
64 |
| -func getConfig() Config { |
65 |
| - var cfg = Config{} |
66 |
| - Ddir := RootDir() |
67 |
| - configPath, err := filepath.Abs(Ddir + "/config/config.yml") |
68 |
| - log.Debug(configPath) |
69 |
| - if err != nil { |
70 |
| - log.Fatal("Could not find config in: ", configPath) |
71 |
| - } |
72 |
| - file, err := ioutil.ReadFile(configPath) |
73 |
| - err = yaml.Unmarshal([]byte(file), &cfg) |
74 |
| - if err != nil { |
75 |
| - log.Fatal("Could not read file in: ", configPath) |
76 |
| - } |
77 |
| - |
78 |
| - return cfg |
79 |
| -} |
80 |
| - |
81 |
| -func GetConfig() (Config, error) { |
82 |
| - var cfg = Config{} |
83 |
| - Ddir := RootDir() |
84 |
| - configPath, err := filepath.Abs(Ddir + "/config/config.yml") |
85 |
| - log.Debug(configPath) |
86 |
| - if err != nil { |
87 |
| - return Config{}, nil |
88 |
| - } |
89 |
| - file, err := ioutil.ReadFile(configPath) |
90 |
| - err = yaml.Unmarshal([]byte(file), &cfg) |
91 |
| - if err != nil { |
92 |
| - return Config{}, nil |
93 |
| - } |
94 |
| - |
95 |
| - return cfg, nil |
96 |
| -} |
0 commit comments