1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-10 00:20:02 +00:00
mondash/storage/adapter.go

44 lines
1 KiB
Go
Raw Normal View History

package storage
2015-07-06 19:41:21 +00:00
import (
"fmt"
"net/url"
2015-07-06 19:41:21 +00:00
"github.com/pkg/errors"
2015-07-06 19:41:21 +00:00
)
// 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
// 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(uri string) (Storage, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, errors.Wrap(err, "Invalid storage URI")
}
switch u.Scheme {
2015-07-06 19:41:21 +00:00
case "s3":
return NewS3Storage(u), nil
2015-07-06 20:08:27 +00:00
case "file":
return NewFileStorage(u), nil
2015-07-06 19:41:21 +00:00
}
return nil, errors.Errorf("Storage %q not found", u.Scheme)
2015-07-06 19:41:21 +00:00
}