Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mLock

Go Report Card GoDoc

mlock empowers users to enforce locks on the same critical section based on different types, providing a flexible and effective way to control access and maintain concurrency in diverse scenarios.

Features

  • Obtain locks based on different keys.
  • Automatically cleans up unused locks at regular intervals.

Installation

To use mlock in your Golang project, you can simply run:

go get -u github.com/kimbbakar/mlock

Usage

Importing the Package

import "github.com/kimbbakar/mlock"

Initializing and Cleaning Up Locks

Before using mlock, it's recommended to set up a cleanup routine to remove unused locks periodically. This can be done using the KeepClean function:

interval := 30 * time.Minute
mlock.KeepClean(&interval)

This sets up a cleanup routine to run every 30 minutes. You can customize the cleanup interval as needed.

Obtaining and Releasing Locks

To obtain a lock based on a key, use the Lock function:

mlock.Lock("your_key_here")
defer mlock.Unlock("your_key_here")

Example

package main

import (
	"fmt"
	"time"

	"github.com/kimbbakar/mlock"
)

func main() {
	// Set up cleanup routine
	interval := 30 * time.Minute
	mlock.KeepClean(&interval)

	// Obtain a lock
	mlock.Lock("example_key")
	defer mlock.Unlock("example_key")

	// Your critical section here
	fmt.Println("Lock acquired, performing operations...")
}

Contribution

Contributions are welcome! If you find any issues or have suggestions for improvement, feel free to open an issue or create a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Multi lock for controlling resource share based on user group

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages