filelock

package
v0.0.0-...-f47aed8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Go file locking

Overview

Exclusive file locks with timeouts using flock.

Example

  // Try to obtain an exclusive file lock with a timeout
  lock := filelock.FileLock{Path: "example.lock", Timeout: time.Second * 1}
  err := lock.Lock()
  if err != nil {
    if err == ErrLockTimeout {
      // Lock timeout
    }

    // Other error
  }

  // Lock obtained successfully, must be released.
  defer lock.Unlock()

See tests for more examples.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockTimeout = errors.New("timeout obtaining lock")
View Source
var ErrNotLocked = errors.New("not locked")

Functions

This section is empty.

Types

type FileLock

type FileLock struct {
	Path    string
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*FileLock) Lock

func (l *FileLock) Lock() error

func (*FileLock) Unlock

func (l *FileLock) Unlock() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL