{"id":17281506,"url":"https://github.com/sumory/idgen","last_synced_at":"2025-04-14T10:02:37.524Z","repository":{"id":24271646,"uuid":"27665944","full_name":"sumory/idgen","owner":"sumory","description":"id generator based on 'snowflake'","archived":false,"fork":false,"pushed_at":"2014-12-09T08:21:23.000Z","size":152,"stargazers_count":29,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T23:12:44.284Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/sumory.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":"2014-12-07T10:02:00.000Z","updated_at":"2022-09-27T04:01:12.000Z","dependencies_parsed_at":"2022-08-22T14:40:31.825Z","dependency_job_id":null,"html_url":"https://github.com/sumory/idgen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumory%2Fidgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumory%2Fidgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumory%2Fidgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumory%2Fidgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sumory","download_url":"https://codeload.github.com/sumory/idgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860331,"owners_count":21173342,"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-10-15T09:46:03.105Z","updated_at":"2025-04-14T10:02:37.467Z","avatar_url":"https://github.com/sumory.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## id generator\n\n[![Build Status](https://travis-ci.org/sumory/idgen.svg?branch=master)](https://travis-ci.org/sumory/idgen) [![](http://gocover.io/_badge/github.com/sumory/idgen)](http://gocover.io/github.com/sumory/idgen) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/sumory/idgen/master/LICENSE)\n\n#### 介绍\n\n - 基于`snowflake`算法实现的id生成器\n - 这是go版本，java版本可查看[IdWorker.java](https://github.com/sumory/uc/blob/master/src/com/sumory/uc/id/IdWorker.java)\n\n\n\n\n#### 使用\n\ngo get github.com/sumory/idgen\n\n使用前请先了解`snowflake`算法，并知晓其注意事项.\n\n\n##### 基本使用\n\n每个由idgen生成的id都是int64的正整数，且每个id都可以解析得到它的生成者的标识`workerId`.\n\n```go\nworkerId := 1\nerr, idWorker := idgen.NewIdWorker(workerId)\nerr, nextId := idWorker.NextId()\n```\n\n##### 获取short Id\n\nidgen使用[baseN4go](https://github.com/sumory/baseN4go)缩短id，具体参见baseN4go使用方法.\n\n```go\nworkerId := 1\nerr, idWorker := idgen.NewIdWorker(workerId)\nerr, nextId := idWorker.ShortId()\n```\n\n##### 获取生成器标识workerId\n\n```go\nworkerId := 1\nerr, idWorker := idgen.NewIdWorker(workerId)\nerr, nextId := idWorker.NextId()\nwId := idWorker.WorkerId(newId)//wId == workerId\n```\n\n##### 其它\n参见测试文件[idgen_test.go](./idgen_test.go)和源文件\n\n\n\n\n#### 测试\n\n需要[goconvey](https://github.com/smartystreets/goconvey)支持\n\n```shell\ngo get github.com/smartystreets/goconvey\ngo test -v -cover // or $GOPATH/bin/goconvey\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumory%2Fidgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumory%2Fidgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumory%2Fidgen/lists"}