{"id":46078489,"url":"https://github.com/kei2100/locker","last_synced_at":"2026-03-01T15:07:08.894Z","repository":{"id":57705368,"uuid":"489860241","full_name":"kei2100/locker","owner":"kei2100","description":" An interface and implementations of named lock for exclusivity control between processes and threads.","archived":false,"fork":false,"pushed_at":"2022-06-05T13:10:54.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-21T03:16:53.937Z","etag":null,"topics":["go","golang","lock","mysql","postgresql"],"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/kei2100.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-05-08T06:03:01.000Z","updated_at":"2023-02-03T09:38:23.000Z","dependencies_parsed_at":"2022-09-06T11:50:21.536Z","dependency_job_id":null,"html_url":"https://github.com/kei2100/locker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kei2100/locker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kei2100%2Flocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kei2100%2Flocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kei2100%2Flocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kei2100%2Flocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kei2100","download_url":"https://codeload.github.com/kei2100/locker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kei2100%2Flocker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29973305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T15:06:50.263Z","status":"ssl_error","status_checked_at":"2026-03-01T15:06:18.879Z","response_time":124,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["go","golang","lock","mysql","postgresql"],"created_at":"2026-03-01T15:07:08.203Z","updated_at":"2026-03-01T15:07:08.882Z","avatar_url":"https://github.com/kei2100.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"locker\n=======\n\n## Description\n\nlocker provides an interface and implementations of named lock for exclusivity control between processes and threads.\n\n```go\nfunc ExampleLocker() {\n\t// setup *sql.DB\n\tdb := setupPostgres()\n\tdefer db.Close()\n\n\t// Acquire the lock by specified key. (Using PostgreSQL pg_advisory_lock)\n\tkey := randHex(16)\n\tlocker := postgres.NewLocker(db)\n\tlock, err := locker.Get(context.Background(), key)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to acquire: %+v\", err))\n\t}\n\t// Releases the lock at the end of the function\n\tdefer lock.Release()\n\tfmt.Println(\"lock acquired\")\n\n\t// The same key will be blocked until the lock is released\n\tdone := make(chan interface{})\n\tgo func() {\n\t\tdefer close(done)\n\t\tctx, cancel := context.WithTimeout(context.Background(), time.Second)\n\t\tdefer cancel()\n\t\tlock, err := locker.Get(ctx, key)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tpanic(fmt.Sprintf(\"unexpected err: %+v\", err))\n\t\t}\n\t\tlock.Release()\n\t\tfmt.Println(\"unexpected lock acquired\")\n\t}()\n\t\u003c-done\n\n\t// Output:\n\t// lock acquired\n}\n```\n\n## Lock implementations\n\nCurrently provides following implementations.\n\n* postgres.Locker\n  * postgres.Locker provides a simple lock mechanism using PostgreSQL [pg_advisory_lock](https://www.postgresql.org/docs/14/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS)\n  * Recommend that using the [pgx](https://github.com/jackc/pgx) PostgreSQL Driver\n* mysql.Locker\n  * mysql.Locker provides a simple lock mechanism using MySQL [GET_LOCK](https://dev.mysql.com/doc/refman/8.0/en/locking-functions.html#function_get-lock)\n\n## Installation\n\n```bash\n$ go get github.com/kei2100/locker\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei2100%2Flocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkei2100%2Flocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkei2100%2Flocker/lists"}