github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/pkg/config/config.go (about) 1 package config 2 3 import ( 4 "github.com/abolfazlbeh/zhycan/internal/config" 5 "time" 6 ) 7 8 // InitializeManager - Create a new config manager instance and wait to initialize it 9 func InitializeManager(configBasePath string, configInitialMode string, configEnvPrefix string) error { 10 err := config.CreateManager(configBasePath, configInitialMode, configEnvPrefix) 11 if err != nil { 12 return err 13 } 14 15 for { 16 flag := config.GetManager().IsInitialized() 17 if flag { 18 break 19 } 20 time.Sleep(200 * time.Millisecond) 21 } 22 23 return nil 24 } 25 26 // GetName - returns service instance name based on config 27 func GetName() string { 28 if config.GetManager().IsInitialized() { 29 return config.GetManager().GetName() 30 } 31 32 return "" 33 } 34 35 // GetOperationType - returns operation type which could be `dev`, `prod` 36 func GetOperationType() string { 37 if config.GetManager().IsInitialized() { 38 return config.GetManager().GetOperationType() 39 } 40 41 return "" 42 } 43 44 // GetHostName - returns hostname based on config 45 func GetHostName() string { 46 if config.GetManager().IsInitialized() { 47 return config.GetManager().GetHostName() 48 } 49 50 return "" 51 } 52 53 // Get - get value of the key in specific category 54 func Get(category string, name string) (interface{}, error) { 55 return config.GetManager().Get(category, name) 56 } 57 58 // Set - set value in category by specified key 59 func Set(category string, name string, value interface{}) error { 60 return config.GetManager().Set(category, name, value) 61 } 62 63 // IsInitialized - iterate over all config wrappers and see all initialised correctly 64 func IsInitialized() bool { 65 return config.GetManager().IsInitialized() 66 } 67 68 // GetAllInitializedModuleList - get list of names that initialized truly 69 func GetAllInitializedModuleList() []string { 70 return config.GetManager().GetAllInitializedModuleList() 71 } 72 73 // ManualLoadConfig - load manual config from the path and add to the current dict 74 func ManualLoadConfig(configBasePath string, configName string) error { 75 return config.GetManager().ManualLoadConfig(configBasePath, configName) 76 }