Provide easier way for locking file storage
This commit is contained in:
parent
83587ca0f8
commit
b4c0df187e
|
@ -44,9 +44,7 @@ func main() {
|
|||
}
|
||||
|
||||
var store tusd.DataStore
|
||||
store = filestore.FileStore{
|
||||
Path: dir,
|
||||
}
|
||||
store = filestore.New(dir)
|
||||
|
||||
if storeSize > 0 {
|
||||
store = limitedstore.New(storeSize, store)
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/tus/tusd"
|
||||
"github.com/tus/tusd/lockingstore"
|
||||
"github.com/tus/tusd/uid"
|
||||
)
|
||||
|
||||
|
@ -24,10 +25,25 @@ var defaultFilePerm = os.FileMode(0775)
|
|||
// methods.
|
||||
type FileStore struct {
|
||||
// Relative or absolute path to store files in. FileStore does not check
|
||||
// whether the path exists, you os.MkdirAll in this case on your own.
|
||||
// whether the path exists, use os.MkdirAll in this case on your own.
|
||||
Path string
|
||||
}
|
||||
|
||||
// New creates a new file based storage backend. The directory specified will
|
||||
// be used as the only storage entry. This method does not check
|
||||
// whether the path exists, use os.MkdirAll to ensure.
|
||||
// In addition, a locking mechanism is provided using lockingstore.LockingStore
|
||||
// and FileLocker.
|
||||
func New(path string) tusd.DataStore {
|
||||
store := FileStore{path}
|
||||
locker := FileLocker{path}
|
||||
|
||||
return lockingstore.LockingStore{
|
||||
DataStore: &store,
|
||||
Locker: &locker,
|
||||
}
|
||||
}
|
||||
|
||||
func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
|
||||
id = uid.Uid()
|
||||
info.ID = id
|
||||
|
|
Loading…
Reference in New Issue