update vendor/

This commit is contained in:
Ettore Di Giacinto
2019-11-25 20:32:33 +01:00
parent 08897b5105
commit a674c6515c
10 changed files with 246 additions and 0 deletions

41
vendor/github.com/marcsauter/single/single.go generated vendored Normal file
View File

@@ -0,0 +1,41 @@
// package single provides a mechanism to ensure, that only one instance of a program is running
package single
import (
"errors"
"log"
"os"
)
var (
// ErrAlreadyRunning -- the instance is already running
ErrAlreadyRunning = errors.New("the program is already running")
// Lockfile -- the lock file to check
Lockfile string
)
// Single represents the name and the open file descriptor
type Single struct {
name string
file *os.File
}
// New creates a Single instance
func New(name string) *Single {
return &Single{name: name}
}
// Lock tries to obtain an exclude lock on a lockfile and exits the program if an error occurs
func (s *Single) Lock() {
if err := s.CheckLock(); err != nil {
log.Fatal(err)
}
}
// Unlock releases the lock, closes and removes the lockfile. All errors will be reported directly.
func (s *Single) Unlock() {
if err := s.TryUnlock(); err != nil {
log.Print(err)
}
}