{"id":13825926,"url":"https://github.com/koding/tunnel","last_synced_at":"2025-04-05T11:11:09.085Z","repository":{"id":32828846,"uuid":"36421890","full_name":"koding/tunnel","owner":"koding","description":"Tunnel proxy package in Go","archived":false,"fork":false,"pushed_at":"2023-10-20T13:43:58.000Z","size":140,"stargazers_count":327,"open_issues_count":7,"forks_count":72,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-29T10:08:55.148Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koding.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}},"created_at":"2015-05-28T07:26:42.000Z","updated_at":"2025-02-15T23:45:58.000Z","dependencies_parsed_at":"2024-01-07T22:49:00.062Z","dependency_job_id":"708d0b21-915d-4946-9624-0f642c1356b8","html_url":"https://github.com/koding/tunnel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Ftunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Ftunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Ftunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koding%2Ftunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koding","download_url":"https://codeload.github.com/koding/tunnel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325693,"owners_count":20920714,"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-08-04T09:01:29.317Z","updated_at":"2025-04-05T11:11:09.051Z","avatar_url":"https://github.com/koding.png","language":"Go","funding_links":[],"categories":["\u003ca id=\"01e6651181d405ecdcd92a452989e7e0\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"9d6789f22a280f5bb6491d1353b02384\"\u003e\u003c/a\u003e隧道\u0026\u0026穿透"],"readme":"# Tunnel [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/koding/tunnel) [![Go Report Card](https://goreportcard.com/badge/github.com/koding/tunnel)](https://goreportcard.com/report/github.com/koding/tunnel) [![Build Status](http://img.shields.io/travis/koding/tunnel.svg?style=flat-square)](https://travis-ci.org/koding/tunnel)\n\nTunnel is a server/client package that enables to proxy public connections to\nyour local machine over a tunnel connection from the local machine to the\npublic server. What this means is, you can share your localhost even if it\ndoesn't have a Public IP or if it's not reachable from outside. \n\nIt uses the excellent [yamux](https://github.com/hashicorp/yamux) package to\nmultiplex connections between server and client.\n\nThe project is under active development, please vendor it if you want to use it.\n\n# Usage\n\nThe tunnel package consists of two parts. The `server` and the `client`. \n\nServer is the public facing part. It's type that satisfies the `http.Handler`.\nSo it's easily pluggable into existing servers. \n\n\nLet assume that you setup your DNS service so all `*.example.com` domains route\nto your server at the public IP `203.0.113.0`. Let us first create the server\npart:\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/koding/tunnel\"\n)\n\nfunc main() {\n\tcfg := \u0026tunnel.ServerConfig{}\n\tserver, _ := tunnel.NewServer(cfg)\n\tserver.AddHost(\"sub.example.com\", \"1234\")\n\thttp.ListenAndServe(\":80\", server)\n}\n```\n\nOnce you create the `server`, you just plug it into your server. The only\ndetail here is to map a virtualhost to a secret token. The secret token is the\nonly part that needs to be known for the client side.\n\nLet us now create the client side part:\n\n```go\npackage main\n\nimport \"github.com/koding/tunnel\"\n\nfunc main() {\n\tcfg := \u0026tunnel.ClientConfig{\n\t\tIdentifier: \"1234\",\n\t\tServerAddr: \"203.0.113.0:80\",\n\t}\n\n\tclient, err := tunnel.NewClient(cfg)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tclient.Start()\n}\n```\n\nThe `Start()` method is by default blocking. As you see you, we just passed the\nserver address and the secret token. \n\nNow whenever someone hit `sub.example.com`, the request will be proxied to the\nmachine where client is running and hit the local server running `127.0.0.1:80`\n(assuming there is one). If someone hits `sub.example.com:3000` (assume your\nserver is running at this port), it'll be routed to `127.0.0.1:3000`\n\nThat's it. \n\nThere are many options that can be changed, such as a static local address for\nyour client. Have alook at the\n[documentation](http://godoc.org/github.com/koding/tunnel)\n\n\n# Protocol\n\nThe server/client protocol is written in the [spec.md](spec.md) file. Please\nhave a look for more detail.\n\n\n## License\n\nThe BSD 3-Clause License - see LICENSE for more details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Ftunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoding%2Ftunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoding%2Ftunnel/lists"}