{"id":31763992,"url":"https://github.com/dispatchrun/net","last_synced_at":"2025-10-09T23:39:26.502Z","repository":{"id":175062799,"uuid":"648474613","full_name":"dispatchrun/net","owner":"dispatchrun","description":"Go package implementing WASI socket extensions","archived":false,"fork":false,"pushed_at":"2024-10-17T22:19:31.000Z","size":172,"stargazers_count":143,"open_issues_count":6,"forks_count":8,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-14T20:55:23.820Z","etag":null,"topics":["golang","network","socket","wasi","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dispatchrun.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":"2023-06-02T03:59:46.000Z","updated_at":"2024-11-11T02:54:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9d58377-3e4d-48ee-9d43-3a1bb23d5f96","html_url":"https://github.com/dispatchrun/net","commit_stats":null,"previous_names":["stealthrocket/net","dispatchrun/net"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/dispatchrun/net","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dispatchrun%2Fnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dispatchrun%2Fnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dispatchrun%2Fnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dispatchrun%2Fnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dispatchrun","download_url":"https://codeload.github.com/dispatchrun/net/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dispatchrun%2Fnet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002311,"owners_count":26083340,"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-09T02:00:07.460Z","response_time":59,"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":["golang","network","socket","wasi","webassembly"],"created_at":"2025-10-09T23:39:16.571Z","updated_at":"2025-10-09T23:39:26.493Z","avatar_url":"https://github.com/dispatchrun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build](https://github.com/stealthrocket/net/actions/workflows/build.yml/badge.svg)](https://github.com/stealthrocket/net/actions/workflows/build.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/stealthrocket/net.svg)](https://pkg.go.dev/github.com/stealthrocket/net)\n[![Apache 2 License](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)\n\n# net\n\nThis library provides `net.Dial` and `net.Listen` functions for\n[`GOOS=wasip1`][wasip1].\n\nApplications built with this library are compatible with [WasmEdge][wasmedge]\nand [wasi-go][wasi-go] such as [Timecraft][timecraft].\n\n[go-121]:    https://go.dev/blog/go1.21\n[timecraft]: https://github.com/stealthrocket/timecraft\n[wasi-go]:   https://github.com/stealthrocket/wasi-go\n[wasip1]:    https://tip.golang.org/doc/go1.21#wasip1\n[wasmedge]:  https://github.com/WasmEdge/WasmEdge\n\n_Note: `GOOS=wasip1` requires [Go 1.21][go-121]._\n\n## Motivation\n\nThe WASI preview 1 specification has partial support for socket networking,\npreventing a large class of Go applications from running when compiled to\nWebAssembly with `GOOS=wasip1`. Extensions to the base specifications have been\nimplemented by runtimes to enable a wider range of programs to be run as\nWebAssembly modules.\n\nThis package aims to offset Go applications built with `GOOS=wasip1` the\nopportunity to leverage those WASI extensions, by providing high level functions\nsimilar to those found in the standard `net` package to create network clients\nand servers.\n\n## Configuration\n\nWhere possible, the package offers the ability to automatically configure the\nnetwork stack via `init` functions called on package imports. This model is\ncurrently supported for `http` and `mysql` with those imports:\n\n```go\nimport _ \"github.com/stealthrocket/net/http\"\n```\n```go\nimport _ \"github.com/stealthrocket/net/mysql\"\n```\n\nWhen imported, those packages alter the default configuration to install a\ndialer function implemented on top of the WASI socket extensions. When compiled\nto other targets, the import of those packages does nothing.\n\n## Dialing\n\nPackages implementing network clients for various protocols usually support\nconfiguration through the installation of an alternative dial function allowing\nthe application to customize how network connections are established.\n\nThe `wasip1` sub-package provides dial functions matching the signature of those\nimplemented in the standard `net` package to integrate with those configuration\nmechanisms.\n\nThe sub-modules contain examples of how to configure popular Go libraries to\nleverage the dial functions of `wasip1`. Here is an example for a Redis client:\n\n```go\nclient := redis.NewClient(\u0026redis.Options{\n\tAddr:   \"localhost:6379\",\n\tDialer: wasip1.DialContext, // change the dial function to use socket extensions\n})\n```\n\n## Listening\n\nNetwork servers can be created using the `wasip1.Listen` function, which mimics\nthe signature of `net.Listen` but uses WASI socket extensions to create the\n`net.Listener`.\n\nFor example, a program compiled to `GOOS=wasip1` can create a http server by\nfirst constructing a listener and passing it to the server's `Serve` method:\n\n```go\nimport (\n    \"net/http\"\n\n    \"github.com/stealthrocket/net/wasip1\"\n)\n\nfunc main() {\n    listener, err := wasip1.Listen(\"tcp\", \"127.0.0.1:3000\")\n    if err != nil {\n        ...\n    }\n    server := \u0026http.Server{\n        ...\n    }\n    if err := server.Serve(listener); err != nil {\n        ...\n    }\n}\n```\n\nNote that using convenience functions like `http.ListenAndServe` will not\nwork since they are hardcoded to depend on the standard `net` package.\n\n## Name Resolution\n\nThere are two methods available for resolving a set of IP addresses for a\nhostname.\n\n### Pure Go Resolver\n\nThe pure Go name resolver is the default for `GOOS=wasip1`.\n\nAll you need is the following import somewhere in your application:\n\n```go\nimport _ \"github.com/stealthrocket/net/wasip1\"\n```\n\nThe library will then automatically configure the `net.DefaultResolver`.\n\nYou'll then be able to use the lookup functions from the standard\nlibrary (e.g. `net.LookupIP(host)`).\n\n### getaddrinfo\n\nThe `sock_getaddrinfo` host function is used to implement name resolution.\nTo use this method, compile the library with the `getaddrinfo` build tag.\n\nWhen using this method, the standard library resolver **will not work**; you\ncannot use `net.DefaultResolver`, `net.LookupIP`, etc.\n\nNote that `sock_getaddrinfo` may block.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdispatchrun%2Fnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdispatchrun%2Fnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdispatchrun%2Fnet/lists"}