{"id":13471892,"url":"https://github.com/rs/xid","last_synced_at":"2025-09-09T21:19:37.171Z","repository":{"id":37664214,"uuid":"45938451","full_name":"rs/xid","owner":"rs","description":"xid is a globally unique id generator thought for the web","archived":false,"fork":false,"pushed_at":"2025-05-12T18:25:58.000Z","size":91,"stargazers_count":4178,"open_issues_count":17,"forks_count":206,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-08-21T13:39:22.980Z","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/rs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-11-10T20:32:24.000Z","updated_at":"2025-08-18T17:02:10.000Z","dependencies_parsed_at":"2024-08-26T13:11:02.771Z","dependency_job_id":"d40cd07f-95cd-4d75-869a-315542989548","html_url":"https://github.com/rs/xid","commit_stats":{"total_commits":82,"total_committers":43,"mean_commits":"1.9069767441860466","dds":0.7073170731707317,"last_synced_commit":"3f489c48caa63b0312d95aa7ab948abc0da07096"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/rs/xid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fxid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fxid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fxid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fxid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rs","download_url":"https://codeload.github.com/rs/xid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rs%2Fxid/sbom","scorecard":{"id":786814,"data":{"date":"2025-08-11","repo":{"name":"github.com/rs/xid","commit":"475c4816644fb91b4f9e514f817edf5a31fa2551"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/rs/xid/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/rs/xid/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/rs/xid/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/rs/xid/go.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/go.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/rs/xid/go.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T06:18:53.481Z","repository_id":37664214,"created_at":"2025-08-23T06:18:53.481Z","updated_at":"2025-08-23T06:18:53.481Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274365922,"owners_count":25272293,"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-09-09T02:00:10.223Z","response_time":80,"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":"2024-07-31T16:00:50.096Z","updated_at":"2025-09-09T21:19:37.119Z","avatar_url":"https://github.com/rs.png","language":"Go","readme":"# Globally Unique ID Generator\n\n[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/xid) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/xid/master/LICENSE) [![Build Status](https://travis-ci.org/rs/xid.svg?branch=master)](https://travis-ci.org/rs/xid) [![Coverage](http://gocover.io/_badge/github.com/rs/xid)](http://gocover.io/github.com/rs/xid)\n\nPackage xid is a globally unique id generator library, ready to safely be used directly in your server code.\n\nXid uses the Mongo Object ID algorithm to generate globally unique ids with a different serialization ([base32hex](https://datatracker.ietf.org/doc/html/rfc4648#page-10)) to make it shorter when transported as a string:\nhttps://docs.mongodb.org/manual/reference/object-id/\n\n- 4-byte value representing the seconds since the Unix epoch,\n- 3-byte machine identifier,\n- 2-byte process id, and\n- 3-byte counter, starting with a random value.\n\nThe binary representation of the id is compatible with Mongo 12 bytes Object IDs.\nThe string representation is using [base32hex](https://datatracker.ietf.org/doc/html/rfc4648#page-10) (w/o padding) for better space efficiency\nwhen stored in that form (20 bytes). The hex variant of base32 is used to retain the\nsortable property of the id.\n\nXid doesn't use base64 because case sensitivity and the 2 non alphanum chars may be an\nissue when transported as a string between various systems. Base36 wasn't retained either\nbecause 1/ it's not standard 2/ the resulting size is not predictable (not bit aligned)\nand 3/ it would not remain sortable. To validate a base32 `xid`, expect a 20 chars long,\nall lowercase sequence of `a` to `v` letters and `0` to `9` numbers (`[0-9a-v]{20}`).\n\nUUIDs are 16 bytes (128 bits) and 36 chars as string representation. Twitter Snowflake\nids are 8 bytes (64 bits) but require machine/data-center configuration and/or central\ngenerator servers. xid stands in between with 12 bytes (96 bits) and a more compact\nURL-safe string representation (20 chars). No configuration or central generator server\nis required so it can be used directly in server's code.\n\n| Name        | Binary Size | String Size    | Features                                                       |\n| ----------- | ----------- | -------------- | -------------------------------------------------------------- |\n| [UUID]      | 16 bytes    | 36 chars       | configuration free, not sortable                               |\n| [shortuuid] | 16 bytes    | 22 chars       | configuration free, not sortable                               |\n| [Snowflake] | 8 bytes     | up to 20 chars | needs machine/DC configuration, needs central server, sortable |\n| [MongoID]   | 12 bytes    | 24 chars       | configuration free, sortable                                   |\n| xid         | 12 bytes    | 20 chars       | configuration free, sortable                                   |\n\n[UUID]: https://en.wikipedia.org/wiki/Universally_unique_identifier\n[shortuuid]: https://github.com/stochastic-technologies/shortuuid\n[Snowflake]: https://blog.twitter.com/2010/announcing-snowflake\n[MongoID]: https://docs.mongodb.org/manual/reference/object-id/\n\nFeatures:\n\n- Size: 12 bytes (96 bits), smaller than UUID, larger than snowflake\n- Base32 hex encoded by default (20 chars when transported as printable string, still sortable)\n- Non configured, you don't need set a unique machine and/or data center id (configurable if needed)\n- K-ordered\n- Embedded time with 1 second precision\n- Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process\n- Lock-free (i.e.: unlike UUIDv1 and v2)\n\nBest used with [zerolog](https://github.com/rs/zerolog)'s\n[RequestIDHandler](https://godoc.org/github.com/rs/zerolog/hlog#RequestIDHandler).\n\nNotes:\n\n- Xid is dependent on the system time, a monotonic counter and so is not cryptographically secure. If unpredictability of IDs is important, you should not use Xids. It is worth noting that most other UUID-like implementations are also not cryptographically secure. You should use libraries that rely on cryptographically secure sources (like /dev/urandom on unix, crypto/rand in golang), if you want a truly random ID generator.\n- MachineID can be set by the environmental variable `XID_MACHINE_ID` to allow fine tune control over the generation.\n\nReferences:\n\n- http://www.slideshare.net/davegardnerisme/unique-id-generation-in-distributed-systems\n- https://en.wikipedia.org/wiki/Universally_unique_identifier\n- https://blog.twitter.com/2010/announcing-snowflake\n- Python port by [Graham Abbott](https://github.com/graham): https://github.com/graham/python_xid\n- Scala port by [Egor Kolotaev](https://github.com/kolotaev): https://github.com/kolotaev/ride\n- Rust port by [Kaz Yoshihara](https://github.com/kazk): https://github.com/kazk/xid-rs\n- Python wrapper around the Rust port [Aleksandr Shpak](https://github.com/shpaker): https://github.com/shpaker/epyxid\n- Ruby port by [Valar](https://github.com/valarpirai/): https://github.com/valarpirai/ruby_xid\n- Java port by [0xShamil](https://github.com/0xShamil/): https://github.com/0xShamil/java-xid\n- Dart port by [Peter Bwire](https://github.com/pitabwire): https://pub.dev/packages/xid\n- PostgreSQL port by [Rasmus Holm](https://github.com/crholm): https://github.com/modfin/pg-xid\n- Swift port by [Uditha Atukorala](https://github.com/uatuko): https://github.com/uatuko/swift-xid\n- C++ port by [Uditha Atukorala](https://github.com/uatuko): https://github.com/uatuko/libxid\n- Typescript \u0026 Javascript port by [Yiwen AI](https://github.com/yiwen-ai): https://github.com/yiwen-ai/xid-ts\n- Gleam port by [Alexandre Del Vecchio](https://github.com/defgenx): https://github.com/defgenx/gxid\n\n## Install\n\n    go get github.com/rs/xid\n\n## Usage\n\n```go\nguid := xid.New()\n\nprintln(guid.String())\n// Output: 9m4e2mr0ui3e8a215n4g\n```\n\nGet `xid` embedded info:\n\n```go\nguid.Machine()\nguid.Pid()\nguid.Time()\nguid.Counter()\n```\n\n## Benchmark\n\nBenchmark against Go [Maxim Bublis](https://github.com/satori)'s [UUID](https://github.com/satori/go.uuid).\n\n```\nBenchmarkXID        \t20000000\t        91.1 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkXID-2      \t20000000\t        55.9 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkXID-4      \t50000000\t        32.3 ns/op\t      32 B/op\t       1 allocs/op\nBenchmarkUUIDv1     \t10000000\t       204 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkUUIDv1-2   \t10000000\t       160 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkUUIDv1-4   \t10000000\t       195 ns/op\t      48 B/op\t       1 allocs/op\nBenchmarkUUIDv4     \t 1000000\t      1503 ns/op\t      64 B/op\t       2 allocs/op\nBenchmarkUUIDv4-2   \t 1000000\t      1427 ns/op\t      64 B/op\t       2 allocs/op\nBenchmarkUUIDv4-4   \t 1000000\t      1452 ns/op\t      64 B/op\t       2 allocs/op\n```\n\nNote: UUIDv1 requires a global lock, hence the performance degradation as we add more CPUs.\n\n## Licenses\n\nAll source code is licensed under the [MIT License](https://raw.github.com/rs/xid/master/LICENSE).\n","funding_links":[],"categories":["Members","Go","UUID","开源类库","Generation","Utility"],"sub_categories":["Utility/Miscellaneous","UUID","Go","Fail injection","实用程序/Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fxid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frs%2Fxid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frs%2Fxid/lists"}