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.

34 lines
818 B

9 years ago
7 years ago
9 years ago
9 years ago
9 years ago
7 years ago
9 years ago
9 years ago
  1. package db
  2. import "fmt"
  3. //-----------------------------------------------------------------------------
  4. // Main entry
  5. const (
  6. LevelDBBackendStr = "leveldb" // legacy, defaults to goleveldb unless +gcc
  7. CLevelDBBackendStr = "cleveldb"
  8. GoLevelDBBackendStr = "goleveldb"
  9. MemDBBackendStr = "memdb"
  10. FSDBBackendStr = "fsdb" // using the filesystem naively
  11. )
  12. type dbCreator func(name string, dir string) (DB, error)
  13. var backends = map[string]dbCreator{}
  14. func registerDBCreator(backend string, creator dbCreator, force bool) {
  15. _, ok := backends[backend]
  16. if !force && ok {
  17. return
  18. }
  19. backends[backend] = creator
  20. }
  21. func NewDB(name string, backend string, dir string) DB {
  22. db, err := backends[backend](name, dir)
  23. if err != nil {
  24. panic(fmt.Sprintf("Error initializing DB: %v", err))
  25. }
  26. return db
  27. }