You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
681 B
39 lines
681 B
package store
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"git.aiterp.net/rpdata/api/internal/config"
|
|
)
|
|
|
|
var initMuted sync.Mutex
|
|
var hasInitialized bool
|
|
|
|
// Init initalizes the store
|
|
func Init() error {
|
|
initMuted.Lock()
|
|
defer initMuted.Unlock()
|
|
if hasInitialized {
|
|
return nil
|
|
}
|
|
|
|
conf := config.Global()
|
|
|
|
dbconf := conf.Database
|
|
err := ConnectDB(dbconf.Host, dbconf.Port, dbconf.Db, dbconf.Username, dbconf.Password, dbconf.Mechanism)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sconf := conf.Space
|
|
if sconf.Enabled {
|
|
err = ConnectSpace(sconf.Host, sconf.AccessKey, sconf.SecretKey, sconf.Bucket, sconf.MaxSize, sconf.Root)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
hasInitialized = true
|
|
|
|
return nil
|
|
}
|