From f3fca6e29cca3ae9a80a108b71ba9f6e21b9f7ac Mon Sep 17 00:00:00 2001 From: brianchennn Date: Tue, 30 May 2023 07:49:51 +0000 Subject: [PATCH] Add ReadUERoutingConfig() in factory.go --- cmd/main.go | 6 ++++++ pkg/factory/factory.go | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) 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 +}