Files
oc-lib/config/conf.go
2026-02-03 15:56:39 +01:00

53 lines
1.1 KiB
Go

package config
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 {
APIPort int
NATSUrl string
MongoUrl string
MongoDatabase string
Host string
Port string
LokiUrl string
LogLevel string
Whitelist bool
PrivateKeyPath string
PublicKeyPath 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(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string, port int) *Config {
GetConfig().MongoUrl = mongoUrl
GetConfig().MongoDatabase = database
GetConfig().NATSUrl = natsUrl
GetConfig().LokiUrl = lokiUrl
GetConfig().LogLevel = logLevel
GetConfig().Whitelist = true
GetConfig().APIPort = port
return GetConfig()
}