{"id":31532691,"url":"https://github.com/floatdrop/demux","last_synced_at":"2025-10-04T03:57:59.216Z","repository":{"id":301588574,"uuid":"1009707917","full_name":"floatdrop/demux","owner":"floatdrop","description":"Static and dynamic demultiplexer","archived":false,"fork":false,"pushed_at":"2025-07-19T09:06:38.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-19T14:57:36.203Z","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/floatdrop.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":"2025-06-27T15:18:44.000Z","updated_at":"2025-07-19T09:05:02.000Z","dependencies_parsed_at":"2025-06-27T17:28:23.330Z","dependency_job_id":"51ea7c8d-9371-4937-a30a-3071de9ae575","html_url":"https://github.com/floatdrop/demux","commit_stats":null,"previous_names":["floatdrop/demux"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/floatdrop/demux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fdemux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fdemux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fdemux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fdemux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatdrop","download_url":"https://codeload.github.com/floatdrop/demux/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fdemux/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278262443,"owners_count":25957938,"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-10-04T02:00:05.491Z","response_time":63,"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-10-04T03:57:48.506Z","updated_at":"2025-10-04T03:57:59.211Z","avatar_url":"https://github.com/floatdrop.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# demux\n\n[![CI](https://github.com/floatdrop/demux/actions/workflows/ci.yaml/badge.svg)](https://github.com/floatdrop/demux/actions/workflows/ci.yaml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/floatdrop/demux)](https://goreportcard.com/report/github.com/floatdrop/demux)\n[![Go Reference](https://pkg.go.dev/badge/github.com/floatdrop/demux.svg)](https://pkg.go.dev/github.com/floatdrop/demux)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n`demux` is a lightweight Go package that provides flexible and generic demultiplexing (fan-out) utilities for channels. It allows you to route items from a single input channel to multiple output channels based on dynamic or static keys.\n\n## Features\n\n- **Dynamic Demuxing**: Automatically spawn goroutines for each unique key, with dedicated channels.\n- **Static Demuxing**: Route messages to pre-defined channels based on their keys.\n- **Generic**: Uses Go generics for maximum flexibility.\n\n## Installation\n\n```bash\ngo get github.com/floatdrop/demux\n```\n\n## Usage\n\n### Dynamic Demuxing\n\n`Dynamic` demuxes messages from an input channel to a dynamically created set of output channels, one per key. Each unique key launches a dedicated goroutine running `consumeFunc`.\n\n```golang\ndemux.Dynamic(input, func(msg MyType) string {\n    return msg.UserID // or any key\n}, func(key string, ch \u003c-chan MyType) {\n    for msg := range ch { // start consuming messages with same UserID\n        fmt.Printf(\"Consumer for %s got: %+v\\n\", key, msg)\n    }\n})\n```\n\n### Static Demuxing\n\n`Static` demuxes messages based on a key and routes them to pre-defined channels in a map.\n\n```golang\nchannels := map[string]chan MyType{\n    \"alpha\": make(chan MyType),\n    \"beta\":  make(chan MyType),\n}\n\ngo demux.Static(input, func(msg MyType) string {\n    return msg.Group\n}, channels)\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fdemux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatdrop%2Fdemux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fdemux/lists"}