Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.gitignore | H A D | 20-Jan-2021 | 266 | 25 | 19 | |
LICENSE | H A D | 20-Jan-2021 | 1.1 KiB | 23 | 17 | |
README.md | H A D | 20-Jan-2021 | 987 | 46 | 31 | |
go.mod | H A D | 20-Jan-2021 | 57 | 4 | 2 | |
lock.go | H A D | 20-Jan-2021 | 320 | 18 | 13 | |
lock_example.go | H A D | 20-Jan-2021 | 512 | 33 | 23 | |
lock_posix.go | H A D | 20-Jan-2021 | 789 | 39 | 27 | |
lock_test.go | H A D | 20-Jan-2021 | 1.1 KiB | 56 | 44 | |
lock_windows.go | H A D | 20-Jan-2021 | 768 | 36 | 23 |
README.md
1# go-singleinstance 2 3Cross plateform library to have only one instance of a software (based on python's [tendo](https://github.com/pycontribs/tendo/blob/master/tendo/singleton.py)). 4 5## Usage 6 7```go 8package main 9 10import ( 11 "fmt" 12 "time" 13 14 "github.com/allan-simon/go-singleinstance" 15) 16 17func main() { 18 lockFile, err := singleinstance.CreateLockFile("plop.lock") 19 if err != nil { 20 fmt.Println("An instance already exists") 21 return 22 } 23 defer lockFile.Close() 24 25 fmt.Println("Sleeping...") 26 time.Sleep(10 * time.Second) 27 fmt.Println("Done") 28} 29``` 30 31If you try to launch it twice, the second instance will fail. 32 33## Thanks 34 35For the python library trendo, from which I've shamelessly adapted the code. 36 37## Contribution 38 39Don't be afraid if it says "last commit 2 years ago", this library is made to be small 40and simple so it's unlikely it changes after some times, however I'm pretty reactive 41on github overall, so feel free to use issues to ask question, propose patch etc. :) 42 43## License 44 45MIT 46