{"id":24108223,"url":"https://github.com/srahkmli/gosnowflake","last_synced_at":"2025-09-04T00:33:02.433Z","repository":{"id":271357538,"uuid":"913172380","full_name":"srahkmli/gosnowflake","owner":"srahkmli","description":" a Go package for generating unique IDs based on the Snowflake algorithm. This release lays the foundation for high-throughput and distributed ID generation with a range of configurable options.","archived":false,"fork":false,"pushed_at":"2025-01-08T08:26:27.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T09:53:27.653Z","etag":null,"topics":["go","golang","idgenerator","snowflake","snowflake-twitter"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/srahkmli/gosnowflake","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/srahkmli.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-07T07:08:46.000Z","updated_at":"2025-01-15T23:50:43.000Z","dependencies_parsed_at":"2025-01-12T02:00:42.934Z","dependency_job_id":null,"html_url":"https://github.com/srahkmli/gosnowflake","commit_stats":null,"previous_names":["srahkmli/gosnowflake"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/srahkmli/gosnowflake","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srahkmli%2Fgosnowflake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srahkmli%2Fgosnowflake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srahkmli%2Fgosnowflake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srahkmli%2Fgosnowflake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srahkmli","download_url":"https://codeload.github.com/srahkmli/gosnowflake/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srahkmli%2Fgosnowflake/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273533785,"owners_count":25122633,"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-03T02:00:09.631Z","response_time":76,"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":["go","golang","idgenerator","snowflake","snowflake-twitter"],"created_at":"2025-01-10T23:26:30.363Z","updated_at":"2025-09-04T00:33:02.425Z","avatar_url":"https://github.com/srahkmli.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snowflake\n\nSnowflake is a Go package for generating unique IDs based on the Snowflake algorithm. It provides flexibility to configure custom epochs, node IDs, and sequence bit sizes, making it ideal for distributed systems requiring unique, high-throughput ID generation.\n\n## Features\n\n- **Thread-safe** ID generation.\n- Configurable node and sequence bit sizes.\n- Custom epoch for timestamp calculations.\n- ID decomposition into timestamp, node ID, and sequence components.\n- Optional base62-encoded IDs of specific lengths.\n\n## Installation\n\nInstall the package using `go get`:\n\n```sh\ngo get github.com/srahkmli/gosnowflake\n```\n\n## Usage\n\n### Basic Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/srahkmli/gosnowflake\"\n)\n\nfunc main() {\n\tcfg := snowflake.Config{\n\t\tEpoch:        time.Now().Add(-time.Hour).UnixMilli(),\n\t\tNodeID:       1,\n\t\tNodeBits:     10,\n\t\tSequenceBits: 12,\n\t}\n\n\tss, err := snowflake.NewSnowFlake(cfg)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to initialize Snowflake: %v\", err)\n\t}\n\n\tid, err := ss.GenerateID()\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to generate ID: %v\", err)\n\t}\n\n\tfmt.Printf(\"Generated ID: %d\\n\", id)\n}\n```\n\n### Custom ID Length\n\nGenerate a base62-encoded ID with a specific length:\n\n```go\ncustomID, err := ss.GenerateCustomID(16)\nif err != nil {\n\tlog.Fatalf(\"Failed to generate custom ID: %v\", err)\n}\nfmt.Printf(\"Generated Custom ID: %s\\n\", customID)\n```\n\n### Decomposing an ID\n\nExtract the timestamp, node ID, and sequence from a generated ID:\n\n```go\ntimestamp, nodeID, sequence := ss.DecomposeID(id)\nfmt.Printf(\"Timestamp: %d, Node ID: %d, Sequence: %d\\n\", timestamp, nodeID, sequence)\n```\n\n## Testing\n\nRun the included tests to verify the functionality:\n\n```sh\ngo test ./...\n```\n\n## Configuration\n\nThe `Config` struct allows for the following options:\n\n- **Epoch**: Start time for ID generation in milliseconds.\n- **NodeID**: Unique identifier for this generator instance.\n- **NodeBits**: Number of bits allocated for the node ID.\n- **SequenceBits**: Number of bits allocated for the sequence.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrahkmli%2Fgosnowflake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrahkmli%2Fgosnowflake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrahkmli%2Fgosnowflake/lists"}