factory.go 707 B

12345678910111213141516171819202122232425262728293031
  1. package storage
  2. import (
  3. "fmt"
  4. dbStorage "dbview/service/internal/common/manager/storage/db_storage"
  5. )
  6. // StorageType 存储类型
  7. type StorageType string
  8. const (
  9. FileStorage StorageType = "file"
  10. DBStorage StorageType = "db"
  11. )
  12. // NewDBStorage 创建数据库存储管理器
  13. func NewDBStorage(dbPath string) (StorageInterface, error) {
  14. return dbStorage.NewStorageManager(dbPath)
  15. }
  16. // GetStorage 根据类型创建存储管理器
  17. func GetStorage(storageType StorageType, configPath, dbPath string) (StorageInterface, error) {
  18. switch storageType {
  19. case DBStorage:
  20. return dbStorage.NewStorageManager(dbPath)
  21. default:
  22. return nil, fmt.Errorf("不支持的存储类型: %s", storageType)
  23. }
  24. }