32 lines
614 B
Go
32 lines
614 B
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Storage interface {
|
|
GetUserSubscriptions(userid string) ([]IncentiveSubscription, error)
|
|
SubscribeIncentive(incentive_subscription IncentiveSubscription) error
|
|
|
|
Migrate() 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
|
|
case "psql":
|
|
s, err := NewPostgresqlStorage(cfg)
|
|
return s, err
|
|
default:
|
|
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
|
|
}
|
|
}
|