dndex/storage/driver/driver.go

30 lines
684 B
Go

package driver
import (
"context"
"local/dndex/config"
"strings"
"go.mongodb.org/mongo-driver/bson"
)
type Driver interface {
Find(context.Context, string, interface{}) (chan bson.Raw, error)
Update(context.Context, string, interface{}, interface{}) error
Insert(context.Context, string, interface{}) error
Delete(context.Context, string, interface{}) error
}
func New(path ...string) Driver {
if len(path) == 0 {
path = []string{config.New().DBURI}
}
switch strings.ToLower(config.New().DriverType) {
case "mongo":
return NewMongo(path[0])
case "boltdb":
return NewBoltDB(path[0])
}
panic("unknown driver type " + strings.ToLower(config.New().DriverType))
}