diff --git a/cmd/main.go b/cmd/main.go index 10228bc6..0112fc16 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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 diff --git a/pkg/factory/factory.go b/pkg/factory/factory.go index 14012507..35e57da0 100644 --- a/pkg/factory/factory.go +++ b/pkg/factory/factory.go @@ -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 @@ -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 +}