{"id":20850579,"url":"https://github.com/multiformats/go-multistream","last_synced_at":"2025-04-08T01:35:49.040Z","repository":{"id":33257937,"uuid":"36902392","full_name":"multiformats/go-multistream","owner":"multiformats","description":"an implementation of the multistream protocol in go","archived":false,"fork":false,"pushed_at":"2025-03-29T08:32:30.000Z","size":2456,"stargazers_count":42,"open_issues_count":10,"forks_count":29,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-01T00:33:59.741Z","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/multiformats.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}},"created_at":"2015-06-05T00:06:27.000Z","updated_at":"2025-03-28T13:06:29.000Z","dependencies_parsed_at":"2024-11-14T19:32:52.182Z","dependency_job_id":"e96b0358-56f8-4208-8d9c-115b1ff3f3a3","html_url":"https://github.com/multiformats/go-multistream","commit_stats":null,"previous_names":["whyrusleeping/go-multistream"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiformats%2Fgo-multistream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiformats%2Fgo-multistream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiformats%2Fgo-multistream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multiformats%2Fgo-multistream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multiformats","download_url":"https://codeload.github.com/multiformats/go-multistream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761051,"owners_count":20991531,"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-11-18T03:10:18.610Z","updated_at":"2025-04-08T01:35:49.021Z","avatar_url":"https://github.com/multiformats.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-multistream\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\n[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)\n[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n[![GoDoc](https://godoc.org/github.com/multiformats/go-multistream?status.svg)](https://godoc.org/github.com/multiformats/go-multistream)\n[![Travis CI](https://img.shields.io/travis/multiformats/go-multistream.svg?style=flat-square\u0026branch=master)](https://travis-ci.org/multiformats/go-multistream)\n[![codecov.io](https://img.shields.io/codecov/c/github/multiformats/go-multistream.svg?style=flat-square\u0026branch=master)](https://codecov.io/github/multiformats/go-multistream?branch=master)\n\n\u003e an implementation of the multistream protocol in go\n\nThis package implements a simple stream router for the multistream-select protocol.\nThe protocol is defined [here](https://github.com/multiformats/multistream-select).\n\n## Table of Contents\n\n\n- [Install](#install)\n- [Usage](#usage)\n- [Maintainers](#maintainers)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n`go-multistream` is a standard Go module which can be installed with:\n\n```sh\ngo get github.com/multiformats/go-multistream\n```\n\n## Usage\n\n### Example\n\nThis example shows how to use a multistream muxer. A muxer uses user-added handlers to handle different \"protocols\". The first step when interacting with a connection handler by the muxer is to select the protocol (the example uses `SelectProtoOrFail`). This will then let the muxer use the right handler.\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"net\"\n\n\tms \"github.com/multiformats/go-multistream\"\n)\n\n// This example creates a multistream muxer, adds handlers for the protocols\n// \"/cats\" and \"/dogs\" and exposes it on a localhost:8765. It then opens connections\n// to that port, selects the protocols and tests that the handlers are working.\nfunc main() {\n\tmux := ms.NewMultistreamMuxer[string]()\n\tmux.AddHandler(\"/cats\", func(proto string, rwc io.ReadWriteCloser) error {\n\t\tfmt.Fprintln(rwc, proto, \": HELLO I LIKE CATS\")\n\t\treturn rwc.Close()\n\t})\n\tmux.AddHandler(\"/dogs\", func(proto string, rwc io.ReadWriteCloser) error {\n\t\tfmt.Fprintln(rwc, proto, \": HELLO I LIKE DOGS\")\n\t\treturn rwc.Close()\n\t})\n\n\tlist, err := net.Listen(\"tcp\", \":8765\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tgo func() {\n\t\tfor {\n\t\t\tcon, err := list.Accept()\n\t\t\tif err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\n\t\t\tgo mux.Handle(con)\n\t\t}\n\t}()\n\n\t// The Muxer is ready, let's test it\n\tconn, err := net.Dial(\"tcp\", \":8765\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create a new multistream to talk to the muxer\n\t// which will negotiate that we want to talk with /cats\n\tmstream := ms.NewMSSelect(conn, \"/cats\")\n\tcats, err := ioutil.ReadAll(mstream)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"%s\", cats)\n\tmstream.Close()\n\n\t// A different way of talking to the muxer\n\t// is to manually selecting the protocol ourselves\n\tconn, err = net.Dial(\"tcp\", \":8765\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer conn.Close()\n\terr = ms.SelectProtoOrFail(\"/dogs\", conn)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdogs, err := ioutil.ReadAll(conn)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"%s\", dogs)\n\tconn.Close()\n}\n```\n\n## Contribute\n\nContributions welcome. Please check out [the issues](https://github.com/multiformats/go-multistream/issues).\n\nCheck out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\nSmall note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## License\n\n[MIT](LICENSE) © 2016 Jeromy Johnson\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiformats%2Fgo-multistream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultiformats%2Fgo-multistream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultiformats%2Fgo-multistream/lists"}