git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/singleinstance/singleinstance_example_test.go (about)

     1  package singleinstance
     2  
     3  import "log"
     4  
     5  // ExampleNew is an example how to use singleinstance
     6  func ExampleNew() {
     7  	// create a new lockfile in /var/lock/filename
     8  	one := New("filename", WithLockPath("/tmp"))
     9  
    10  	// lock and defer unlocking
    11  	if err := one.Lock(); err != nil {
    12  		log.Fatal(err)
    13  	}
    14  
    15  	// run
    16  
    17  	if err := one.Unlock(); err != nil {
    18  		log.Println(err)
    19  	}
    20  }