1
0
Fork 0
mirror of https://github.com/Luzifer/gallery.git synced 2024-11-12 16:02:43 +00:00
gallery/storage.go

43 lines
921 B
Go
Raw Normal View History

2018-04-28 16:51:55 +00:00
package main
import (
"errors"
"fmt"
"io"
"net/url"
"strings"
)
type storage interface {
// WriteFile takes the content of a file and writes it into the underlying
// storage system.
WriteFile(filepath string, content io.Reader, contentType string) error
// ReadFile retrieves a file from the underlying storage, needs to return
// errFileNotFound when file is not present.
ReadFile(filepath string) (io.ReadCloser, error)
}
var errFileNotFound = errors.New("File not found")
func getStorageByURI(uri string) (storage, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}
switch u.Scheme {
case "file":
return fileStorage{path: strings.TrimPrefix(uri, "file://")}, nil
case "log":
// NoOp storage: Only logs requests
return logStorage{}, nil
case "s3":
return s3StorageFromURI(uri), nil
2018-04-28 16:51:55 +00:00
default:
return nil, fmt.Errorf("Storage scheme %q not defined", u.Scheme)
}
}