From 8eb6843b404dfb3935b3cf09c564c6db8d494480 Mon Sep 17 00:00:00 2001 From: brianchennn <46628572+brianchennn@users.noreply.github.com> Date: Wed, 31 May 2023 12:43:19 +0800 Subject: [PATCH] Add ReadUERoutingConfig() in factory.go (#77) --- 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 +}