{"id":18438262,"url":"https://github.com/pumpkinseed/locker","last_synced_at":"2025-04-14T13:16:14.916Z","repository":{"id":64307558,"uuid":"124244546","full_name":"PumpkinSeed/locker","owner":"PumpkinSeed","description":"A distributed lock service client for etcd","archived":false,"fork":false,"pushed_at":"2018-03-08T15:25:01.000Z","size":2899,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T13:16:08.891Z","etag":null,"topics":["distributed-lock","distributed-storage","distributed-systems"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PumpkinSeed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T14:03:08.000Z","updated_at":"2021-01-30T06:42:22.000Z","dependencies_parsed_at":"2023-01-15T11:00:29.326Z","dependency_job_id":null,"html_url":"https://github.com/PumpkinSeed/locker","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumpkinSeed%2Flocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumpkinSeed%2Flocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumpkinSeed%2Flocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PumpkinSeed%2Flocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PumpkinSeed","download_url":"https://codeload.github.com/PumpkinSeed/locker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886343,"owners_count":21177645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-lock","distributed-storage","distributed-systems"],"created_at":"2024-11-06T06:19:17.686Z","updated_at":"2025-04-14T13:16:14.868Z","avatar_url":"https://github.com/PumpkinSeed.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# locker\n\nA distributed lock service client for [etcd](https://github.com/coreos/etcd).\n\n**Forked from github.com/jagregory/locker**\n\n#### Features\n\n- Lock/Unlock mechanism\n- Migrate to `github.com/coreos/etcd/clientv3`\n- TTL\n\n\n[![Godoc](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/PumpkinSeed/locker)\n[![Build Status](https://travis-ci.org/PumpkinSeed/locker.svg?branch=master)](https://travis-ci.org/PumpkinSeed/locker)\n\n## What? Why?\n\nA distributed lock service is somewhat self-explanatory. Locking (mutexes) as a service that's distributed across a cluster.\n\nWhat a lock service gives you is a key-value store with locking semantics, and a mechanism for watching state changes. The distributed part of a distributed lock service is thanks to the etcd underpinnings, and it simply means your locks are persisted across a cluster.\n\n## Usage\n\n### Creating a lock and release it with the Unlock\n\n```go\nimport \"github.com/PumpkinSeed/locker\"\n\n// Add etcd cluster nodes\nvar machines = []string{\"http://127.0.0.1:2379\", \"http://127.0.0.1:2380\", \"http://127.0.0.1:2381\"}\n\n// Add timeout for etcd DialTimeout option\nvar timeout = int64(5)\n\n// Add ttl (time-to-live)\nvar ttl = int64(5)\n\n// Create the locker client.\nclient, err := locker.New(machines, timeout, ttl, context.Background())\n\nvar key = \"1231231-123123-123\"\nquit := make(chan bool)\nreport := client.Lock(key, locker.DefaultValue, quit)\n// report has a Msg and an Err field, Msg will contains 'success' or 'fail' operations.\n```\n\n### Report\n\n- Report returned by the `Lock`, it has a Msg and an Err field\n- The Msg Success if the key not locked yet, and Fail if the key locked\n- The Err will return an error occured among the lock mechanism\n\n### Releasing the lock\n\nThe third argument to `Lock` is a `quit` channel. Push anything into this channel to kill the locking, which will delete the locked key from the etcd.\n\n```go\nclient.Unlock(key, quit)\n```\n\n### Watching a lock (deprecated)\n\nAn interesting aspect of lock services is the ability to watch a lock that isn't owned by you. A service can alter its behaviour depending on the value of a lock. You can use the `Watch` function to watch the value of a lock.\n\n```go\nvalueChanges := make(chan string)\ngo client.Watch(\"key\", valueChanges, nil)\n\nselect {\ncase change := \u003c-valueChanges\n\tfmt.Printf(\"Lock value changed: %s\", change)\n}\n```\n\nQuitting works the same way as `Lock`.\n\n## Contribution\n\n- Docker environment provided for testing etcd in the docker directory.\n- utils.go has a debug option, currently in `false` if it's `true` than it will log debug messages to the os.Stdout\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpkinseed%2Flocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpumpkinseed%2Flocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpumpkinseed%2Flocker/lists"}