1
0
Fork 0
mirror of https://github.com/Luzifer/gallery.git synced 2024-12-22 19:01:23 +00:00
gallery/storage.go
Knut Ahlers 2411dbad8e
Implement S3 storage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-04-28 20:22:51 +02:00

42 lines
921 B
Go

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
default:
return nil, fmt.Errorf("Storage scheme %q not defined", u.Scheme)
}
}