2022-09-05 05:27:52 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Storage interface {
|
|
|
|
CreateEvent(Event) error
|
|
|
|
GetEvent(string) (*Event, error)
|
|
|
|
GetEvents(namespaces []string) ([]Event, error)
|
2022-10-17 03:00:35 +00:00
|
|
|
AddSubscription(eventid string, subscription Subscription) error
|
2023-02-01 15:04:10 +00:00
|
|
|
UpdateSubscription(eventid string, subscriber string, deletesubscription Subscription) error
|
2023-02-01 08:58:37 +00:00
|
|
|
UpdateEvent(Event) error
|
2023-09-06 11:34:43 +00:00
|
|
|
GetSubscriptionByUser(subscriber string) ([]Subscription, error)
|
2022-09-05 05:27:52 +00:00
|
|
|
}
|
|
|
|
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
|
2023-05-09 08:42:52 +00:00
|
|
|
case "psql":
|
|
|
|
s, err := NewPostgresqlStorage(cfg)
|
|
|
|
return s, err
|
2022-09-05 05:27:52 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
|
|
|
}
|
|
|
|
}
|