This repository has been archived on 2025-03-01. You can view files and clone it, but cannot push or open issues or pull requests.
trantor/lib/storage/storage.go
2017-05-21 10:16:51 +00:00

34 lines
566 B
Go

package storage
import (
"io"
"os"
)
type Store interface {
Create(id string, name string) (io.WriteCloser, error)
Store(id string, file io.Reader, name string) (size int64, err error)
Get(id string, name string) (File, error)
Delete(id string) error
}
type File interface {
io.ReadCloser
io.ReaderAt
Stat() (fi os.FileInfo, err error)
}
func Init(path string) (Store, error) {
st := new(fsStore)
st.path = path
_, err := os.Stat(path)
if err != nil {
err = mkstore(st.path)
}
return st, err
}
func RO(st Store) Store {
return &roStore{st}
}