43 lines
759 B
Go
43 lines
759 B
Go
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 {
|
|
MongoUrl string
|
|
MongoDatabase string
|
|
}
|
|
|
|
func (c Config) GetUrl() string {
|
|
return c.MongoUrl
|
|
}
|
|
|
|
func (c Config) GetDatabase() string {
|
|
return c.MongoDatabase
|
|
}
|
|
|
|
var instance *Config
|
|
var once sync.Once
|
|
|
|
func GetConfig() *Config {
|
|
once.Do(func() {
|
|
instance = &Config{}
|
|
})
|
|
return instance
|
|
}
|
|
|
|
func SetConfig(url string, database string) *Config {
|
|
once.Do(func() {
|
|
instance = &Config{
|
|
MongoUrl: url,
|
|
MongoDatabase: database,
|
|
}
|
|
})
|
|
return instance
|
|
}
|