github.com/gofrs/flock
Package flock implements a thread-safe interface for file locking. It also includes a non-blocking TryLock() function to allow locking without blocking execution. Package flock is released under the BSD 3-Clause License. See the LICENSE file for more details. While using this library, remember that the locking behaviors are not guaranteed to be the same on each platform. For example, some UNIX-like operating systems will transparently convert a shared lock to an exclusive lock. If you Unlock() the flock from a location where you believe that you have the shared lock, you may accidentally drop the exclusive lock.
Readme
flock
implements a thread-safe sync.Locker interface for file locking. It also
includes a non-blocking TryLock() function to allow locking without blocking execution.
flock
is released under the BSD 3-Clause License. See the LICENSE
file for more details.
This package makes use of the context
package that was introduced in Go 1.7. As such, this
package has an implicit dependency on Go 1.7+.
go get -u github.com/gofrs/flock
import "github.com/gofrs/flock"
fileLock := flock.New("/var/lock/go-lock.lock")
locked, err := fileLock.TryLock()
if err != nil {
// handle locking error
}
if locked {
// do work
fileLock.Unlock()
}
For more detailed usage information take a look at the package API docs on GoDoc.
FAQs
Package flock implements a thread-safe interface for file locking. It also includes a non-blocking TryLock() function to allow locking without blocking execution. Package flock is released under the BSD 3-Clause License. See the LICENSE file for more details. While using this library, remember that the locking behaviors are not guaranteed to be the same on each platform. For example, some UNIX-like operating systems will transparently convert a shared lock to an exclusive lock. If you Unlock() the flock from a location where you believe that you have the shared lock, you may accidentally drop the exclusive lock.
We found that github.com/gofrs/flock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.