From 3451d56ead6e57f503962b876c89284f1fb73a90 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sat, 10 Sep 2022 17:33:30 +0200 Subject: ref: Create a storage interface This `Storage` interface will define all the interactions with the storage system. For now I plan to support native file system through go's standard library and Nextcloud through *webdav*. So this is the first step in that direction. --- storage/storage.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 storage/storage.go (limited to 'storage/storage.go') diff --git a/storage/storage.go b/storage/storage.go new file mode 100644 index 0000000..b788efb --- /dev/null +++ b/storage/storage.go @@ -0,0 +1,30 @@ +package storage + +import ( + "crypto/sha256" + "fmt" + "io" +) + +type WalkMode int + +const ( + Folder WalkMode = iota + File + FileFolder +) + +type Storage interface { + Walk(path string, walkMode WalkMode) <-chan string + Get(path string) (io.Reader, error) +} + +func CalculateSHA256(r io.Reader) (string, error) { + h := sha256.New() + if _, err := io.Copy(h, r); err != nil { + return "", err + } + + return fmt.Sprintf("%x", h.Sum(nil)), nil + +} -- cgit v1.2.3