2024-08-21 10:04:09 +02:00
|
|
|
package tools
|
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-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-08-21 10:04:09 +02:00
|
|
|
func SetConfig(url string, database string, natsUrl string) *Config {
|
2024-07-18 16:18:27 +02:00
|
|
|
once.Do(func() {
|
|
|
|
instance = &Config{
|
|
|
|
MongoUrl: url,
|
|
|
|
MongoDatabase: database,
|
2024-08-21 10:04:09 +02:00
|
|
|
NATSUrl: natsUrl,
|
2024-07-18 16:18:27 +02:00
|
|
|
}
|
|
|
|
})
|
2024-07-18 11:56:54 +02:00
|
|
|
return instance
|
|
|
|
}
|