naman.gupta | ad87645 | 2023-05-09 15:31:52 +0530 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2023 Samsung |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | |
| 17 | This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | platform project (RICP). |
| 19 | ================================================================================== |
| 20 | */ |
| 21 | package config |
| 22 | |
| 23 | import ( |
| 24 | "os" |
| 25 | |
| 26 | "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1" |
| 27 | "github.com/spf13/viper" |
| 28 | ) |
| 29 | |
| 30 | type Configuration struct { |
| 31 | LogLevel string |
| 32 | Name string |
| 33 | MaxSize int |
| 34 | ThreadType int |
| 35 | LowLatency bool |
| 36 | FastAck bool |
| 37 | MaxRetryOnFailure int |
| 38 | Port int |
| 39 | } |
| 40 | |
| 41 | func ParseConfiguration() *Configuration { |
| 42 | viper.SetConfigType("yaml") |
| 43 | viper.SetConfigName("configuration") |
| 44 | configFile := os.Getenv("A1_CONFIG_FILE") |
| 45 | viper.SetConfigFile(configFile) |
| 46 | err := viper.ReadInConfig() |
| 47 | if err != nil { |
| 48 | a1.Logger.Info("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err) |
| 49 | } |
| 50 | |
| 51 | config := Configuration{} |
| 52 | config.LogLevel = viper.GetString("log-level") |
| 53 | viper.SetDefault("log-level", "info") |
| 54 | config.Name = viper.GetString("NAME") |
| 55 | viper.SetDefault("NAME", "") |
| 56 | config.MaxSize = viper.GetInt("MAX_SIZE") |
| 57 | viper.SetDefault("MAX_SIZE", 65534) |
| 58 | config.ThreadType = viper.GetInt("THREAD_TYPE") |
| 59 | viper.SetDefault("THREAD_TYPE", 0) |
| 60 | config.LowLatency = viper.GetBool("LOW_LATENCY") |
| 61 | viper.SetDefault("LOW_LATENCY", false) |
| 62 | config.FastAck = viper.GetBool("FAST_ACK") |
| 63 | viper.SetDefault("FAST_ACK", false) |
| 64 | config.MaxRetryOnFailure = viper.GetInt("MAX_RETRY_ON_FAILURE") |
| 65 | viper.SetDefault("MAX_RETRY_ON_FAILURE", 1) |
| 66 | config.Port = viper.GetInt("PORT") |
| 67 | viper.SetDefault("PORT", 4561) |
| 68 | return &config |
| 69 | } |