Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
/ go-file-lock Public archive

Golang file lock to run only one instance of an application at a time

License

Notifications You must be signed in to change notification settings

MichaelS11/go-file-lock

Repository files navigation

Go file lock

GoDoc Reference Build Status Coverage Go Report Card

Golang file lock to run only one instance of an application at a time

Get

go get github.com/MichaelS11/go-file-lock

Usage

import (
	"github.com/MichaelS11/go-file-lock"
)

func Run() error {

  lockHandle, err := filelock.New("myLockFile.lock")

  if err != nil && err == filelock.ErrFileIsBeingUsed {
    return nil
  }

  if err != nil {
    return err
  }
  
  # do main program

  return lockHandle.Unlock()
  
}

If you want the current directory of your application, you can do:

baseDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))

About

Golang file lock to run only one instance of an application at a time

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages