GraphQL API and utilities for the rpdata project
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

  1. package store
  2. import (
  3. "sync"
  4. "git.aiterp.net/rpdata/api/internal/config"
  5. )
  6. var initMuted sync.Mutex
  7. var hasInitialized bool
  8. // Init initalizes the store
  9. func Init() error {
  10. initMuted.Lock()
  11. defer initMuted.Unlock()
  12. if hasInitialized {
  13. return nil
  14. }
  15. conf := config.Global()
  16. dbconf := conf.Database
  17. err := ConnectDB(dbconf.Host, dbconf.Port, dbconf.Db, dbconf.Username, dbconf.Password, dbconf.Mechanism)
  18. if err != nil {
  19. return err
  20. }
  21. sconf := conf.Space
  22. if sconf.Enabled {
  23. err = ConnectSpace(sconf.Host, sconf.AccessKey, sconf.SecretKey, sconf.Bucket, sconf.MaxSize, sconf.Root)
  24. if err != nil {
  25. return err
  26. }
  27. }
  28. hasInitialized = true
  29. return nil
  30. }