Skip to content

Commit

Permalink
Add ReadUERoutingConfig() in factory.go (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchennn authored May 31, 2023
1 parent da88f64 commit 8eb6843
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func action(cliCtx *cli.Context) error {
}
factory.SmfConfig = cfg

ueRoutingCfg, err := factory.ReadUERoutingConfig(cliCtx.String("uerouting"))
if err != nil {
return err
}
factory.UERoutingConfig = ueRoutingCfg

smf, err := service.NewApp(cfg)
if err != nil {
return err
Expand Down
19 changes: 18 additions & 1 deletion pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func InitConfigFactory(f string, cfg *Config) error {
return nil
}

func InitRoutingConfigFactory(f string, cfg *Config) error {
func InitRoutingConfigFactory(f string, cfg *RoutingConfig) error {
if f == "" {
// Use default config path
f = SmfDefaultUERoutingPath
Expand Down Expand Up @@ -71,3 +71,20 @@ func ReadConfig(cfgPath string) (*Config, error) {

return cfg, nil
}

func ReadUERoutingConfig(cfgPath string) (*RoutingConfig, error) {
ueRoutingCfg := &RoutingConfig{}
if err := InitRoutingConfigFactory(cfgPath, ueRoutingCfg); err != nil {
return nil, fmt.Errorf("ReadConfig [%s] Error: %+v", cfgPath, err)
}
if _, err := ueRoutingCfg.Validate(); err != nil {
validErrs := err.(govalidator.Errors).Errors()
for _, validErr := range validErrs {
logger.CfgLog.Errorf("%+v", validErr)
}
logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]")
return nil, fmt.Errorf("Config validate Error")
}

return ueRoutingCfg, nil
}

0 comments on commit 8eb6843

Please sign in to comment.