carpool-incentives/storage/storage.go

32 lines
614 B
Go
Raw Normal View History

2023-03-12 23:23:59 +00:00
package storage
import (
"fmt"
"github.com/spf13/viper"
)
type Storage interface {
GetUserSubscriptions(userid string) ([]IncentiveSubscription, error)
SubscribeIncentive(incentive_subscription IncentiveSubscription) error
2023-05-02 18:06:02 +00:00
Migrate() error
2023-03-12 23:23:59 +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
2023-05-07 23:16:08 +00:00
case "psql":
s, err := NewPostgresqlStorage(cfg)
return s, err
2023-03-12 23:23:59 +00:00
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}
}