Documentation ¶
Overview ¶
Package single provides a mechanism to ensure, that only one instance of a program is running
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrAlreadyRunning another instance of is already running ErrAlreadyRunning = errors.New("another instance is already running") )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Single)
Option configures Single
func WithLockPath ¶
WithLockPath configures the path for the lockfile
type Single ¶
type Single struct {
// contains filtered or unexported fields
}
Single represents the name and the open file descriptor
func New ¶
New creates a Single instance where name is the basename of the lock file (<name>.lock) if no path is given (WithLockPath option) the lock will be created in an operating specific path as <name>.lock
Example ¶
ExampleNew is an example how to use single
// create a new lockfile in /var/lock/filename one, err := New("filename", WithLockPath("/tmp")) if err != nil { log.Fatal(err) } // lock and defer unlocking if err := one.Lock(); err != nil { log.Fatal(err) } // run if err := one.Unlock(); err != nil { log.Println(err) }
Output:
func (*Single) Lock ¶
Lock tries to obtain an exclude lock on a lockfile and exits the program if an error occurs
Click to show internal directories.
Click to hide internal directories.