Documentation ¶
Overview ¶
Package singleinstance provides a mechanism to ensure, that only one instance of a program is running
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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(*SingleInstance)
Option configures Single
func WithLockPath ¶
WithLockPath configures the path for the lockfile
type SingleInstance ¶
type SingleInstance struct {
// contains filtered or unexported fields
}
SingleInstance represents the name and the open file descriptor
func New ¶
func New(name string, opts ...Option) *SingleInstance
New creates a SingleInstance 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 panics if namr is empty
Example ¶
ExampleNew is an example how to use singleinstance
Output:
func (*SingleInstance) Lock ¶
func (s *SingleInstance) Lock() error
Lock tries to obtain an exclude lock on a lockfile and exits the program if an error occurs
func (*SingleInstance) Lockfile ¶
func (s *SingleInstance) Lockfile() string
Lockfile returns the full path of the lock file
func (*SingleInstance) Unlock ¶
func (s *SingleInstance) Unlock() error
Unlock releases the lock, closes and removes the lockfile