Add documentation for MemoryLocker
This commit is contained in:
parent
b03ddd1d4c
commit
47492260e8
|
@ -4,16 +4,21 @@ import (
|
||||||
"github.com/tus/tusd"
|
"github.com/tus/tusd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MemoryLocker persists locks using memory and therefore allowing a simple and
|
||||||
|
// cheap mechansim. Locks will only exist as long as this object is kept in
|
||||||
|
// reference and will be erased if the program exits.
|
||||||
type MemoryLocker struct {
|
type MemoryLocker struct {
|
||||||
locks map[string]bool
|
locks map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new lock memory persistor.
|
||||||
func New() *MemoryLocker {
|
func New() *MemoryLocker {
|
||||||
return &MemoryLocker{
|
return &MemoryLocker{
|
||||||
locks: make(map[string]bool),
|
locks: make(map[string]bool),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LockUpload tries to obtain the exclusive lock.
|
||||||
func (locker *MemoryLocker) LockUpload(id string) error {
|
func (locker *MemoryLocker) LockUpload(id string) error {
|
||||||
|
|
||||||
// Ensure file is not locked
|
// Ensure file is not locked
|
||||||
|
@ -26,6 +31,7 @@ func (locker *MemoryLocker) LockUpload(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnlockUpload releases a lock. If no such lock exists, no error will be returned.
|
||||||
func (locker *MemoryLocker) UnlockUpload(id string) error {
|
func (locker *MemoryLocker) UnlockUpload(id string) error {
|
||||||
// Deleting a non-existing key does not end in unexpected errors or panic
|
// Deleting a non-existing key does not end in unexpected errors or panic
|
||||||
// since this operation results in a no-op
|
// since this operation results in a no-op
|
||||||
|
|
Loading…
Reference in New Issue