oc-lib/config/conf.go

56 lines
1.2 KiB
Go
Raw Normal View History

2024-09-04 10:53:12 +02:00
package config
2024-07-16 10:56:36 +02:00
import "sync"
// ===================================================
// This class has to be updated everytime
// a new configuration variable is defined
// in a componant that imports oc-lib
// ===================================================
type Config struct {
2024-08-21 10:04:09 +02:00
NATSUrl string
2024-07-18 16:14:39 +02:00
MongoUrl string
MongoDatabase string
2024-08-26 11:47:30 +02:00
Host string
Port string
2024-09-04 10:53:12 +02:00
LokiUrl string
LogLevel string
2024-07-18 14:11:13 +02:00
}
func (c Config) GetUrl() string {
2024-07-18 16:14:39 +02:00
return c.MongoUrl
2024-07-18 14:11:13 +02:00
}
func (c Config) GetDatabase() string {
2024-07-18 16:14:39 +02:00
return c.MongoDatabase
2024-07-16 10:56:36 +02:00
}
var instance *Config
var once sync.Once
func GetConfig() *Config {
once.Do(func() {
instance = &Config{}
})
return instance
}
2024-07-18 11:56:54 +02:00
2024-09-04 10:53:12 +02:00
func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *Config {
2024-09-04 14:21:01 +02:00
/*once.Do(func() {
2024-07-18 16:18:27 +02:00
instance = &Config{
2024-09-04 10:53:12 +02:00
MongoUrl: mongoUrl,
2024-07-18 16:18:27 +02:00
MongoDatabase: database,
2024-08-21 10:04:09 +02:00
NATSUrl: natsUrl,
2024-09-04 10:53:12 +02:00
LokiUrl: lokiUrl,
LogLevel: logLevel,
2024-07-18 16:18:27 +02:00
}
2024-09-04 14:21:01 +02:00
})*/
GetConfig().MongoUrl = mongoUrl
GetConfig().MongoDatabase = database
GetConfig().NATSUrl = natsUrl
GetConfig().LokiUrl = lokiUrl
GetConfig().LogLevel = logLevel
return GetConfig()
2024-07-18 11:56:54 +02:00
}