Initial commit
This commit is contained in:
35
storage/storage.go
Normal file
35
storage/storage.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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
|
||||
GetBooking(id string) (*Booking, error)
|
||||
GetBookingsForVehicle(vehicleid string) ([]Booking, error)
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user