{"id":21518208,"url":"https://github.com/ucloud/go-lockfile","last_synced_at":"2025-07-14T02:37:56.152Z","repository":{"id":61679735,"uuid":"553383243","full_name":"ucloud/go-lockfile","owner":"ucloud","description":"A Linux go library to lock cooperating processes based on syscall `flock`","archived":false,"fork":false,"pushed_at":"2022-10-18T11:11:40.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-26T19:05:47.004Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ucloud.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-10-18T06:08:06.000Z","updated_at":"2022-10-18T12:36:40.000Z","dependencies_parsed_at":"2022-10-20T04:15:15.099Z","dependency_job_id":null,"html_url":"https://github.com/ucloud/go-lockfile","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ucloud/go-lockfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fgo-lockfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fgo-lockfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fgo-lockfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fgo-lockfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ucloud","download_url":"https://codeload.github.com/ucloud/go-lockfile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fgo-lockfile/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265233753,"owners_count":23731825,"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":[],"created_at":"2024-11-24T00:50:49.642Z","updated_at":"2025-07-14T02:37:56.124Z","avatar_url":"https://github.com/ucloud.png","language":"Go","readme":"# go-lockfile\n\n[![GoDoc](https://godoc.org/github.com/ucloud/go-lockfile?status.svg)](https://godoc.org/github.com/ucloud/go-lockfile) [![Go Report Card](https://goreportcard.com/badge/github.com/ucloud/go-lockfile)](https://goreportcard.com/report/github.com/ucloud/go-lockfile)\n\nA Linux go library to lock cooperating processes based on syscall [flock](https://man7.org/linux/man-pages/man2/flock.2.html).\n\n## Install\n\n```shell\ngo get github.com/ucloud/go-lockfile\n```\n\n## Usage\n\nA simple example:\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/ucloud/go-lockfile\"\n)\n\nfunc main() {\n\tfl := lockfile.New(\"busy.lock\")\n\tvar err error\n\tfor i := 0; i \u003c 20; i++ {\n\t\terr = fl.TryLock()\n\t\tif err == nil {\n\t\t\tbreak\n\t\t}\n\t\ttime.Sleep(time.Millisecond * 50)\n\t}\n\tif err != nil {\n\t\tif errors.Is(err, lockfile.ErrBusy) {\n\t\t\tfmt.Println(\"The lock is busy\")\n\t\t} else {\n\t\t\tfmt.Printf(\"Unexpected error: %v\\n\", err)\n\t\t}\n\t\tos.Exit(1)\n\t}\n\n\tfmt.Println(\"lock!\")\n\t// Handle your logic\n\ttime.Sleep(time.Second)\n\n\terr = fl.Unlock()\n\tif err != nil {\n\t\tfmt.Printf(\"failed to unlock: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n}\n```\n\n## Documentation\n\nSee: [go-lockfile package](https://pkg.go.dev/github.com/ucloud/go-lockfile)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fgo-lockfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fucloud%2Fgo-lockfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fgo-lockfile/lists"}