{"id":36539387,"url":"https://github.com/xyctruth/lock","last_synced_at":"2026-01-12T05:38:43.906Z","repository":{"id":50330091,"uuid":"518015598","full_name":"xyctruth/lock","owner":"xyctruth","description":"Go distributed lock by etcd","archived":false,"fork":false,"pushed_at":"2022-07-28T08:06:28.000Z","size":21,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T14:20:28.763Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyctruth.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":"2022-07-26T10:30:48.000Z","updated_at":"2023-01-10T11:47:01.000Z","dependencies_parsed_at":"2022-09-18T22:11:34.126Z","dependency_job_id":null,"html_url":"https://github.com/xyctruth/lock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xyctruth/lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyctruth%2Flock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyctruth%2Flock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyctruth%2Flock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyctruth%2Flock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyctruth","download_url":"https://codeload.github.com/xyctruth/lock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyctruth%2Flock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28335226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-01-12T05:38:43.213Z","updated_at":"2026-01-12T05:38:43.899Z","avatar_url":"https://github.com/xyctruth.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lock\n\nGo distributed lock library\n\n## ETCD Drive\n\n```go\nlocker, _ := drive_etcd.NewEtcdLocker(\n    etcdClient.Config{\n        Endpoints: []string{\"http://0.0.0.0:2379\"},\n    },\n)\nlock1, err := locker.Acquire(\"key\")\nif err != nil {\n    fmt.Println(err)\n    return\n}\ndefer lock1.Release()\n\n// Do something\n```\n\n\n获取锁超时时间, 超过此时间没有获取到锁返回 `ErrDeadlineExceeded` 错误\n```go\nlocker.Acquire(key, lock.WithAcquireTimeout(5*time.Second))\n```\n\n非堵塞尝试获取锁，如果没有获取到锁返回 `ErrAlreadyLocked` 错误\n```go\nlocker.Acquire(key, lock.WithTry(true))\n```\n\n锁过期时间，如果为0则会自动续约不会过期，需要手动释放锁\n```go\nlocker.Acquire(key, lock.WithLockTTL(5*time.Second))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyctruth%2Flock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyctruth%2Flock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyctruth%2Flock/lists"}