2024-07-16 10:56:36 +02:00
|
|
|
package oclib
|
|
|
|
|
|
|
|
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-07-18 14:11:13 +02:00
|
|
|
mongoUrl string
|
|
|
|
mongoDatabase string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Config) GetUrl() string {
|
|
|
|
return c.mongoUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Config) GetDatabase() string {
|
|
|
|
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-07-18 13:58:49 +02:00
|
|
|
func SetConfig(url string, database string) *Config {
|
2024-07-18 13:43:41 +02:00
|
|
|
instance = &Config{
|
2024-07-18 14:11:13 +02:00
|
|
|
mongoUrl: url,
|
|
|
|
mongoDatabase: database,
|
2024-07-18 13:43:41 +02:00
|
|
|
}
|
2024-07-18 11:56:54 +02:00
|
|
|
return instance
|
|
|
|
}
|