• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D20-Jan-2021266 2519

LICENSEH A D20-Jan-20211.1 KiB2317

README.mdH A D20-Jan-2021987 4631

go.modH A D20-Jan-202157 42

lock.goH A D20-Jan-2021320 1813

lock_example.goH A D20-Jan-2021512 3323

lock_posix.goH A D20-Jan-2021789 3927

lock_test.goH A D20-Jan-20211.1 KiB5644

lock_windows.goH A D20-Jan-2021768 3623

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