2022-08-11 15:21:32 +00:00
|
|
|
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
|
2022-12-19 08:13:56 +00:00
|
|
|
/*******************************************************/
|
|
|
|
CreateGroupMember(GroupMember) error
|
|
|
|
GetGroupMember(string) (*GroupMember, error)
|
|
|
|
GetGroupsMember([]string) ([]GroupMember, error)
|
|
|
|
GetGroupsMemberByIds([]string) ([]GroupMember, error)
|
|
|
|
UpdateGroupMember(GroupMember) error
|
2023-01-17 14:07:16 +00:00
|
|
|
DeleteGroupMember(string) error
|
2022-08-11 15:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|