{"id":36659084,"url":"https://github.com/takecy/grouping","last_synced_at":"2026-01-12T10:25:34.086Z","repository":{"id":57512335,"uuid":"123668352","full_name":"takecy/grouping","owner":"takecy","description":"simple id grouping package in golang. Useful for AB testing.","archived":false,"fork":false,"pushed_at":"2018-09-17T15:38:18.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T06:45:52.076Z","etag":null,"topics":["abtesting","golang"],"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/takecy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-03T07:04:24.000Z","updated_at":"2020-02-23T23:14:17.000Z","dependencies_parsed_at":"2022-09-26T17:51:38.329Z","dependency_job_id":null,"html_url":"https://github.com/takecy/grouping","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/takecy/grouping","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takecy%2Fgrouping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takecy%2Fgrouping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takecy%2Fgrouping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takecy%2Fgrouping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takecy","download_url":"https://codeload.github.com/takecy/grouping/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takecy%2Fgrouping/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["abtesting","golang"],"created_at":"2026-01-12T10:25:33.355Z","updated_at":"2026-01-12T10:25:34.078Z","avatar_url":"https://github.com/takecy.png","language":"Go","readme":"# grouping\n`grouping` is simple id grouping package in golang. Useful for AB testing.\n\n![](https://img.shields.io/badge/golang-1.11.0-blue.svg?style=flat-square)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/takecy/grouping)\n[![Go Report Card](https://goreportcard.com/badge/github.com/takecy/grouping)](https://goreportcard.com/report/github.com/takecy/grouping)\n[![Build Status](https://travis-ci.org/takecy/grouping.svg?branch=master)](https://travis-ci.org/takecy/grouping)\n\n## Overview\n\nThere are several elements to conduct the AB testing.\n\n### Prepare\n1. Define AB testing (Name, Rate etc...)\n1. Grouping for IDs (e.g. Users)\n\n### Per Request\n1. Decide group of requested id\n1. Separate out\n1. Logging of result\n1. Verification\n1. Return to 1...\n\nThis package provides simple way of `Prepare` and `1. Decide group of id` (e.g. user) based on unique id in server-side.  \n\n### Non Goal\n* Feature flag management\n* Branch processing for groups\n\n\u003cbr/\u003e\n\n## Usage\n\n### Basic usage\n\nsee [example](./example/simple/main.go)\n\n```\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/takecy/grouping\"\n)\n\n// SimpleElem implements `grouping.Elementer`\ntype SimpleElem struct {\n\tname  string\n\tratio int\n}\n\nfunc (e *SimpleElem) GetName() string { return e.name }\nfunc (e *SimpleElem) GetRatio() int   { return e.ratio }\nfunc (e *SimpleElem) SetRatio(r int)  { e.ratio = r }\n\nfunc main() {\n\tgroup := grouping.GroupDefinition{\n\t\t// case: A+B+C=100\n\t\tElems: []grouping.Elementer{\n\t\t\t\u0026SimpleElem{name: \"group-A\", ratio: 10},\n\t\t\t\u0026SimpleElem{name: \"group-B\", ratio: 20},\n\t\t\t\u0026SimpleElem{name: \"group-C\", ratio: 70},\n\t\t},\n\t}\n\n\tg, err := grouping.New(group)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t//\n\t// The same result will be obtained no matter how many times it is executed.\n\t//\n\ttestName := \"welcome_content_test\"\n\n\tuserID1 := \"user-001\"\n\telem1, err := g.GetGroup(userID1, testName)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"elem1: %v\\n\", elem1.GetName()) // group-A\n\n\tuserID2 := \"user-002\"\n\telem2, err := g.GetGroup(userID2, testName)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"elem2: %v\\n\", elem2.GetName()) // group-C\n}\n\n```\n\n### Advanced usage\n\n#### Default specification\n\nYou can define groups with a total ratio less than 100.  \nIn this case, You can specify `default` for cases not matches any group.  \n\nsee [example](./example/default_elem/main.go)\n\n```\n\tgroup := grouping.GroupDefinition{\n\t\t// this means 20% of all\n\t\tElems: []grouping.Elementer{\n\t\t\t\u0026SimpleElem{name: \"group-A\", ratio: 20},\n\t\t},\n\t\t// not match\n\t\tDefaultElem: \u0026SimpleElem{name: \"group-default\"},\n\t}\n\n\tg, err := grouping.New(group)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n```\n\n\n#### Customize hash function\n\nYou can customize function for generate hash.\n\nsee [example](./example/hash_func/main.go)\n\n```\n\tgroup := grouping.GroupDefinition{\n\t\t// case: A+B=100\n\t\tElems: []grouping.Elementer{\n\t\t\t\u0026SimpleElem{name: \"group-A\", ratio: 30},\n\t\t\t\u0026SimpleElem{name: \"group-B\", ratio: 70},\n\t\t},\n\t}\n\t// replace hash function\n\thashFunc := func(seed string) uint32 {\n\t\treturn uint32(len(seed))\n\t}\n\n\tg, err := grouping.NewWithHashFunc(group, hashFunc)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n```\n\n\u003cbr/\u003e\n\n## LICENSE\n[MIT](./LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakecy%2Fgrouping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakecy%2Fgrouping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakecy%2Fgrouping/lists"}