{"id":30210157,"url":"https://github.com/nrednav/cuid2","last_synced_at":"2025-08-13T19:57:56.176Z","repository":{"id":176689094,"uuid":"655123888","full_name":"nrednav/cuid2","owner":"nrednav","description":"Secure, collision-resistant ids optimized for horizontal scaling and performance. Next generation UUIDs.","archived":false,"fork":false,"pushed_at":"2025-07-07T03:27:29.000Z","size":169,"stargazers_count":46,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T21:40:15.491Z","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/nrednav.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-18T00:58:44.000Z","updated_at":"2025-07-31T20:00:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"85265a7a-43f6-4176-b983-40cbb28a4eb5","html_url":"https://github.com/nrednav/cuid2","commit_stats":null,"previous_names":["nrednav/cuid2"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nrednav/cuid2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrednav%2Fcuid2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrednav%2Fcuid2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrednav%2Fcuid2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrednav%2Fcuid2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrednav","download_url":"https://codeload.github.com/nrednav/cuid2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrednav%2Fcuid2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270304533,"owners_count":24562082,"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","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"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":"2025-08-13T19:57:31.213Z","updated_at":"2025-08-13T19:57:56.124Z","avatar_url":"https://github.com/nrednav.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cuid2\n\n\u003e Secure, collision-resistant ids optimized for horizontal scaling and performance. Next generation UUIDs.\n\nThis is a port of the JavaScript library [@paralleldrive/cuid2](https://github.com/paralleldrive/cuid2), rewritten in Go.\n\nFor more information about Cuid2, including details about why and how, please refer to the [original documentation](https://github.com/paralleldrive/cuid2).\n\n## Getting Started\n\nWith [Go module](https://github.com/golang/go/wiki/Modules) support, you can add the following import statement to your code:\n\n```go\nimport \"github.com/nrednav/cuid2\"\n```\n\nand then run the following in the root of the repository to fetch the module:\n\n```bash\ngo mod tidy\n```\n\nAlternatively, you can run the following command:\n\n```bash\ngo get -u github.com/nrednav/cuid2\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/nrednav/cuid2\"\n)\n\nfunc main() {\n    // Generate a Cuid with default, secure configuration\n    id := cuid2.Generate()\n\n    // or alternatively, provide your own configuration\n    generate, err := cuid2.Init(\n        cuid2.WithLength(32),\n    )\n\n    if err != nil {\n        fmt.Println(err.Error())\n    }\n\n    // This function generates an id with a length of 32\n    id = generate()\n\n    // Validate\n    cuid2.IsCuid(id)\n}\n```\n\n## Configuration\n\nYou can configure the behavior of the Cuid2 generator by providing the `Init()`\nfunction a series of option functions.\n\n```go\npackage main\n\nimport (\n    \"github.com/nrednav/cuid2\"\n    \"sync/atomic\"\n)\n\n// (Optional) create your own custom counter\ntype Counter struct {\n    value int64\n}\n\nfunc NewCounter(initialCount int64) *Counter {\n    return \u0026Counter{value: initialCount}\n}\n\nfunc (c *Counter) Increment() int64 {\n    return atomic.AddInt64(\u0026sc.value, 1)\n}\n\nfunc main() {\n    generate, err := cuid2.Init(\n        // Adjust the length of generated id, min = 2, max = 32\n        cuid2.WithLength(32),\n\n        // Provide a custom fingerprint that will be used by the id generator to help prevent\n        // collisions when generating id's in a distributed system.\n        cuid2.WithFingerprint(\"hello world\"),\n\n        // Provide a custom session counter that will be used to affect the\n        // entropy of successive id generation calls\n        cuid2.WithSessionCounter(NewCounter(0)),\n\n        // Provide a custom function that generates a floating-point value between 0 and 1\n        // This is useful for providing a deterministic source during testing\n        cuid2.WithRandomFunc(func() float64 { return 0.1234 })\n    )\n}\n```\n\n## Testing\n\nRun the tests with:\n\n```bash\ngo test\n```\n\nThis project also includes a long-running collision and distribution stress\ntest.\n\nThis test is excluded by default. To run the stress test, use the `integration`\nbuild tag:\n\n```bash\ngo test -tags=integration -v -timeout=0\n```\n\nHere's a sample distribution for one pool of generated ids:\n\n\u003cimg width=\"640\" alt=\"histogram of entropy range\" src=\"assets/histogram.png\" /\u003e\n\n## Benchmarks\n\nThe id generation function can be benchmarked for varying id lengths.\n\nTo run a benchmark, use:\n\n```bash\ngo test -run=XYZ -bench=. -benchtime=30s\n```\n\nResults:\n\n\u003cimg width=\"640\" alt=\"benchmarks of id generation\" src=\"assets/benchmark.png\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrednav%2Fcuid2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrednav%2Fcuid2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrednav%2Fcuid2/lists"}