mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-14 02:12:42 +00:00
Knut Ahlers
f3c31476b4
* Update dependencies * Improve code quality * Apply linter advices * Add gzip compression to all requests * Rework frontend * Apply bootswatch theme * Hide historic details when not requested * Remove debugging header * Apply auto-migration of meta fields * Fix broken "last update" time * Pre-sort metrics for frontend / API * Add tooltip with absolute time * Some design fixes * Add tooltip with absolute date to last ok * Implement filters * Apply eslint --fix * Remove unused var * Remove remains of old template engine * Update baked in assets * Update Dockerfile for new version Signed-off-by: Knut Ahlers <knut@ahlers.me>
43 lines
1 KiB
Go
43 lines
1 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// 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 {
|
|
case "s3":
|
|
return NewS3Storage(u), nil
|
|
case "file":
|
|
return NewFileStorage(u), nil
|
|
}
|
|
|
|
return nil, errors.Errorf("Storage %q not found", u.Scheme)
|
|
}
|