fleets/storage/storage.go

39 lines
841 B
Go
Raw Permalink Normal View History

2022-08-12 12:49:16 +00:00
package storage
import (
"fmt"
"github.com/spf13/viper"
)
type Storage interface {
//Vehicles management
CreateVehicle(Vehicle) error
GetVehicle(id string) (*Vehicle, error)
GetVehicles(namespaces []string) ([]Vehicle, error)
//Bookings management
CreateBooking(Booking) error
2022-09-05 05:26:43 +00:00
UpdateBooking(Booking) error
2022-08-12 12:49:16 +00:00
GetBooking(id string) (*Booking, error)
2022-09-05 05:26:43 +00:00
GetBookings() ([]Booking, error)
2022-08-12 12:49:16 +00:00
GetBookingsForVehicle(vehicleid string) ([]Booking, error)
2022-09-05 05:26:43 +00:00
GetBookingsForDriver(driver string) ([]Booking, error)
2022-08-12 12:49:16 +00:00
DeleteBooking(id string) 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
default:
return nil, fmt.Errorf("storage type %v is not supported", storage_type)
}
}