{"modulePath":"github.com/cloudzero/cloudzero-agent","version":"v1.1.0-rc-1","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lock\n\nPackage lock provides an interface for file-based locking.\n\n## Variables\n\n```go\nvar (\n\tErrLockExists          = errors.New(\"lock already exists\")\n\tErrLockStale           = errors.New(\"stale lock detected\")\n\tErrLockLost            = errors.New(\"lock lost\")\n\tErrLockAcquire         = errors.New(\"failed to acquire lock\")\n\tErrLockCorrup          = errors.New(\"corrupt lock file\")\n\tErrMaxRetryExceeded    = errors.New(\"failed to acquire lock, max retries exceeded\")\n\tDefautlStaleTimeout    = time.Millisecond * 500\n\tDefaultRefreshInterval = time.Millisecond * 200\n\tDefaultRetryInterval   = 1 * time.Second\n\tDefaultMaxRetry        = 5\n)\n```\n\n## Functions\n\n```go\nfunc LockDir(ctx context.Context, dirPath string, fn func() error, opts ...FileLockOption) error\n```\nLockDir acquires a lock for the specified directory, executes the function, then releases the lock. The lock file is created within the target directory as \\`.dir.lock\\`.\n\n```go\nfunc LockFile(ctx context.Context, filePath string, fn func() error, opts ...FileLockOption) error\n```\nLockFile acquires a lock for the specified file, executes the function, then releases the lock. The lock file is created in the same directory as \\`${filepath}.lock\\`\n\n## Types\n\n```go\ntype FileLock struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewFileLock(ctx context.Context, filepath string, opts ...FileLockOption) *FileLock\n```\n\n```go\nfunc (fl *FileLock) Acquire() error\n```\n\n```go\nfunc (fl *FileLock) Release() error\n```\n\n```go\ntype FileLockOption func(fl *FileLock)\n```\n\n```go\nfunc WithMaxRetry(retry int) FileLockOption\n```\n\n```go\nfunc WithNoMaxRetry() FileLockOption\n```\n\n```go\nfunc WithRefreshInterval(interval time.Duration) FileLockOption\n```\n\n```go\nfunc WithRetryInterval(interval time.Duration) FileLockOption\n```\n\n```go\nfunc WithStaleTimeout(timeout time.Duration) FileLockOption\n```\n\n","path":"github.com/cloudzero/cloudzero-agent/app/lock","name":"lock","synopsis":"Package lock provides an interface for file-based locking.","isRedistributable":true}
