{"id":15870947,"url":"https://github.com/int128/listener","last_synced_at":"2025-03-16T04:30:28.571Z","repository":{"id":52115181,"uuid":"212471638","full_name":"int128/listener","owner":"int128","description":"Go package to allocate a net.Listener from address candidates or free port","archived":false,"fork":false,"pushed_at":"2025-02-15T05:17:41.000Z","size":143,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T04:54:08.215Z","etag":null,"topics":["golang","network"],"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/int128.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":"2019-10-03T00:57:58.000Z","updated_at":"2025-02-15T05:17:44.000Z","dependencies_parsed_at":"2024-11-25T19:27:48.065Z","dependency_job_id":"717bb22a-093b-40f4-a515-8661c9259c97","html_url":"https://github.com/int128/listener","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.15384615384615385","last_synced_commit":"7e6d32a722b09e13bb989cdf1233f596329aaa8d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/int128%2Flistener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/int128%2Flistener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/int128%2Flistener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/int128%2Flistener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/int128","download_url":"https://codeload.github.com/int128/listener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801680,"owners_count":20350108,"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":["golang","network"],"created_at":"2024-10-06T00:41:02.985Z","updated_at":"2025-03-16T04:30:28.565Z","avatar_url":"https://github.com/int128.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# listener [![go](https://github.com/int128/listener/actions/workflows/go.yaml/badge.svg)](https://github.com/int128/listener/actions/workflows/go.yaml) [![GoDoc](https://godoc.org/github.com/int128/listener?status.svg)](https://godoc.org/github.com/int128/listener)\n\nThis is a Go package to allocate a net.Listener from address candidates.\n\n```sh\ngo get github.com/int128/listener\n```\n\n## Examples\n\n### Allocate a free port\n\nTo allocate a `net.Listener` at a free port on localhost:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/int128/listener\"\n)\n\nfunc main() {\n\tl, err := listener.New(nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer l.Close()\n\n\tfmt.Printf(\"Open %s\", l.URL)\n}\n```\n\n### Allocate a port from candidates\n\nTo allocate a `net.Listener` at a port 18000 or 28000 on localhost:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/int128/listener\"\n)\n\nfunc main() {\n\tl, err := listener.New([]string{\"127.0.0.1:18000\", \"127.0.0.1:28000\"})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer l.Close()\n\n\tfmt.Printf(\"Open %s\", l.URL)\n}\n```\n\nIf port 18000 is already in use, it will allocate port 28000.\n\n\n## Contributions\n\nThis is an open source software.\nFree free to open issues and pull requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fint128%2Flistener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fint128%2Flistener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fint128%2Flistener/lists"}