{"id":15460553,"url":"https://github.com/schollz/golock","last_synced_at":"2025-07-06T03:03:17.811Z","repository":{"id":57491959,"uuid":"140626098","full_name":"schollz/golock","owner":"schollz","description":"Very simple file locking with optional timeouts. :lock: :page_facing_up:","archived":false,"fork":false,"pushed_at":"2020-08-06T20:12:13.000Z","size":13,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T10:35:23.286Z","etag":null,"topics":["file-lock","semaphore","synchronization","threading"],"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/schollz.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-07-11T20:49:28.000Z","updated_at":"2025-02-28T03:02:16.000Z","dependencies_parsed_at":"2022-08-28T11:50:17.747Z","dependency_job_id":null,"html_url":"https://github.com/schollz/golock","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/schollz/golock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fgolock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fgolock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fgolock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fgolock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schollz","download_url":"https://codeload.github.com/schollz/golock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schollz%2Fgolock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263841583,"owners_count":23518481,"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":["file-lock","semaphore","synchronization","threading"],"created_at":"2024-10-01T23:22:32.879Z","updated_at":"2025-07-06T03:03:17.786Z","avatar_url":"https://github.com/schollz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# golock\n\n[![travis](https://travis-ci.org/schollz/golock.svg?branch=master)](https://travis-ci.org/schollz/golock) \n[![go report card](https://goreportcard.com/badge/github.com/schollz/golock)](https://goreportcard.com/report/github.com/schollz/golock) \n[![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://gocover.io/github.com/schollz/golock)\n[![godocs](https://godoc.org/github.com/schollz/golock?status.svg)](https://godoc.org/github.com/schollz/golock) \n\nVery simple (\u003c100 LOC) file locking with optional timeouts. \n\n\n## Install\n\n```\ngo get github.com/schollz/golock\n```\n\n## Usage \n\nInitialize the lock and then obtain it. If you specify the timeout and interval, it will poll at the given interval for the specified time until it successfully gets a lock, otherwise throw an error. If you don't specify the timeout, then it will throw an error immediately if it does not obtain the lock.\n\nIf you get no errors from locking, then you are good to go. Make sure to unlock it when you are done.\n\n```golang\n// first initiate lockfile\nl := golock.New(\n    golock.OptionSetName(\"mylockfile\"), \n    golock.OptionSetInterval(1*time.Millisecond), \n    golock.OptionSetTimeout(60*time.Second),\n)\n\n// lock it\nerr := l.Lock()\nif err != nil {\n    // error means we didn't get the lock\n    // handle it\n}\n\n// do stuff\n\n// unlock it\nerr = l.Unlock()\nif err != nil {\n    panic(err)\n}\n```\n\n## Benchmarks\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/schollz/golock\nBenchmarkLocking-4     200000     12224 ns/op    128 B/op    5 allocs/op\n```\n\n## Contributing\n\nPull requests are welcome. Feel free to...\n\n- Revise documentation\n- Add new features\n- Fix bugs\n- Suggest improvements\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Fgolock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschollz%2Fgolock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschollz%2Fgolock/lists"}