agenda/storage/storage.go

38 lines
901 B
Go

package storage
import (
"fmt"
"github.com/spf13/viper"
)
type Storage interface {
CreateEvent(Event) error
GetEvent(string) (*Event, error)
GetEvents(namespaces []string) ([]Event, error)
AddSubscription(eventid string, subscription Subscription) error
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
UpdateEvent(Event) error
GetSubscriber(subscriber string) ([]Subscription, error)
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
}
type StorageImpl struct {
}
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
case "psql":
s, err := NewPostgresqlStorage(cfg)
return s, err
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}
}