1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-23 04:21:18 +00:00
mondash/storage/adapter.go

48 lines
1.2 KiB
Go
Raw Normal View History

2015-07-06 19:41:21 +00:00
package storage // import "github.com/Luzifer/mondash/storage"
import (
"fmt"
"github.com/Luzifer/mondash/config"
)
// Storage is an interface to have all storage systems compatible to each other
type Storage interface {
Put(dashboardID string, data []byte) error
Get(dashboardID string) ([]byte, error)
Delete(dashboardID string) error
Exists(dashboardID string) (bool, error)
}
2015-07-06 20:08:27 +00:00
// AdapterNotFoundError is a named error for more simple determination which
2015-07-06 19:41:21 +00:00
// type of error is thrown
2015-07-06 20:08:27 +00:00
type AdapterNotFoundError struct {
2015-07-06 19:41:21 +00:00
Name string
}
2015-07-06 20:08:27 +00:00
func (e AdapterNotFoundError) Error() string {
2015-07-06 19:41:21 +00:00
return fmt.Sprintf("Storage '%s' not found.", e.Name)
}
2015-07-06 20:08:27 +00:00
// DashboardNotFoundError signalizes the requested dashboard could not be found
type DashboardNotFoundError struct {
DashboardID string
}
func (e DashboardNotFoundError) Error() string {
return fmt.Sprintf("Dashboard with ID '%s' was not found.", e.DashboardID)
}
2015-07-06 19:41:21 +00:00
// GetStorage acts as a storage factory providing the storage named by input
// name parameter
func GetStorage(cfg *config.Config) (Storage, error) {
switch cfg.Storage {
case "s3":
return NewS3Storage(cfg), nil
2015-07-06 20:08:27 +00:00
case "file":
return NewFileStorage(cfg), nil
2015-07-06 19:41:21 +00:00
}
2015-07-06 20:08:27 +00:00
return nil, AdapterNotFoundError{cfg.Storage}
2015-07-06 19:41:21 +00:00
}