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.

37 lines
654 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. err = ConnectSpace(sconf.Host, sconf.AccessKey, sconf.SecretKey, sconf.Bucket, sconf.MaxSize, sconf.Root)
  23. if err != nil {
  24. return err
  25. }
  26. hasInitialized = true
  27. return nil
  28. }