31 lines
554 B
Go
31 lines
554 B
Go
|
package storage
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/spf13/viper"
|
||
|
)
|
||
|
|
||
|
type Storage interface {
|
||
|
CreateGroup(Group) error
|
||
|
GetGroup(string) (*Group, error)
|
||
|
GetGroups([]string) ([]Group, error)
|
||
|
GetGroupsByIds([]string) ([]Group, error)
|
||
|
UpdateGroup(Group) error
|
||
|
}
|
||
|
|
||
|
func NewStorage(cfg *viper.Viper) (Storage, error) {
|
||
|
var (
|
||
|
storage_type = cfg.GetString("storage.db.type")
|
||
|
)
|
||
|
|
||
|
switch storage_type {
|
||
|
case "mongodb":
|
||
|
s, err := NewMongoDBStorage(cfg)
|
||
|
return s, err
|
||
|
default:
|
||
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
||
|
}
|
||
|
|
||
|
}
|