Skip to content

zoer/locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Locker

Build Status Go Report Card GoDoc

Install

$ go get github.com/zoer/locker

Usage

package main

import (
	"context"
	"log"

	etcd "github.com/coreos/etcd/clientv3"
)

func main() {
	// connect to Etcd instance
	cl, err := clientv3.NewFromURL("127.0.0.1:2379")
	if err != nil {
		log.Fatalf("unable connect to Etcd")
	}

	lkr := NewEtcd(cl)

	// cancel the lock via context timeout after 30 seconds
	ctx, _ := context.WithTimeout(context.TODO(), 30*time.Second)

	l, err := lkr.Lock(ctx, WithKey("lock-key"))
	if err != nil {
		log.Fatalf("unable get a lock: %v", err)
	}
	defer l.Unlock()

	// ...
}

TODO

  • Etcd
  • Consul
  • Redis

About

Distributed locker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published