flock

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package flock provides a portable advisory file lock.

Lock opens or creates a lock file and acquires an exclusive lock on it. The returned release function must be called to unlock and close the file.

Advisory semantics

The lock is advisory: it only serializes callers that also use this package (or otherwise cooperate on the same lock file). A non-cooperating process that has write access to the protected file can ignore the lock and read or write freely. For files containing sensitive data, rely on filesystem permissions (0700 directories, 0600 files) as the primary access control; flock is a coordination primitive, not a mandatory-access gate. The lock file itself is left on disk after release so the next caller can re-acquire it; it is created with 0600 permissions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(path string) (func(), error)

Lock acquires an exclusive advisory lock on path. It creates the lock file with 0600 permissions if it does not exist. The returned release function unlocks and closes the lock file; callers should defer it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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