From: subhash kumar singh Date: Wed, 28 Sep 2022 10:08:33 +0000 (+0000) Subject: Simplify the reading configuration X-Git-Tag: 2.0.0~17 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=d349bbcc5736a3f09091788cbe6afe9cdef116cd;p=ric-plt%2Fricdms.git Simplify the reading configuration Simplify reading configuration by creating model for config. Signed-off-by: subhash kumar singh Change-Id: I2a4b527c36e83dabafe6f32b3f1f1c100cb24215 --- diff --git a/config/config-test.yaml b/config/config-test.yaml index de9d2ad..5e37c1c 100644 --- a/config/config-test.yaml +++ b/config/config-test.yaml @@ -12,4 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -log-level: debug \ No newline at end of file +log-level: debug +onborder-url: "http://127.0.0.1:9191" +mock-server: "127.0.0.1:9191" \ No newline at end of file diff --git a/config/config.yaml b/config/config.yaml index de9d2ad..e47eaca 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -12,4 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. # -log-level: debug \ No newline at end of file +log-level: debug +onborder-url: "http://service-ricplt-xapp-onboarder-http.ricplt:8888/api/v1/onboard" \ No newline at end of file diff --git a/pkg/config/conf.go b/pkg/config/conf.go new file mode 100644 index 0000000..1eff109 --- /dev/null +++ b/pkg/config/conf.go @@ -0,0 +1,50 @@ +//================================================================================== +// Copyright (c) 2022 Samsung +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). +//================================================================================== +// + +package config + +import ( + "fmt" + "io/ioutil" + + "gopkg.in/yaml.v3" +) + +type Conf struct { + LogLevel string `yaml:"log-level"` + OnboardURL string `yaml:"onborder-url"` + MockServer string `yaml:"mock-server"` +} + +func ReadConfiguration(configFile string) (c *Conf, err error) { + yamlFile, err := ioutil.ReadFile(configFile) + if err != nil { + fmt.Printf("error in resolving config file : %+v\n", err) + return nil, err + } + + err = yaml.Unmarshal(yamlFile, &c) + if err != nil { + fmt.Printf("Unmarshal error : %+v\n", err) + return nil, err + } + + return c, err +} diff --git a/pkg/ricdms/ricdms.go b/pkg/ricdms/ricdms.go index 40c2f9d..b15bf01 100644 --- a/pkg/ricdms/ricdms.go +++ b/pkg/ricdms/ricdms.go @@ -25,12 +25,14 @@ import ( "os" mdclog "gerrit.o-ran-sc.org/r/com/golog" + "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/config" ) type ricdms struct { } var Logger *mdclog.MdcLogger +var Config *config.Conf func Init() { var err error @@ -44,9 +46,13 @@ func Init() { if configFile != "" { Logger.ParseFileContent(configFile) + Config, err = config.ReadConfiguration(configFile) + if err != nil { + Logger.Error("Error in parsing config file: %v", err) + } Logger.Info("Logger is initialized with config file : %s", configFile) } else { Logger.LevelSet(mdclog.INFO) - Logger.Info("Logger is initialized without config file.") + Logger.Info("Logger is initialized without config file(%s).", configFile) } }