Skip to content

Commit 2486367

Browse files
author
hzsunshx
committed
add tunnel example
1 parent 98863c2 commit 2486367

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ Libs might be useful
154154
- <https://github.com/koding/tunnel>
155155
- <https://github.com/mmatczuk/go-http-tunnel>
156156
- <https://github.com/inconshreveable/go-tunnel>
157+
- <https://github.com/labstack/tunnel-client> SSH Tunnel
158+
- <https://github.com/gliderlabs/ssh> Easy SSH servers in Golang
157159
158160
## LICENSE
159161
[MIT](LICENSE)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ require (
55
github.com/fatih/color v1.7.0 // indirect
66
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
77
github.com/kr/pty v1.1.3 // indirect
8+
github.com/labstack/tunnel-client v0.2.12
89
github.com/manifoldco/promptui v0.3.2
910
github.com/mattn/go-runewidth v0.0.3 // indirect
1011
github.com/mattn/go-tty v0.0.0-20181127064339-e4f871175a2f
1112
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1213
github.com/pkg/errors v0.8.0
14+
github.com/qiniu/log v0.0.0-20140728010919-a304a74568d6
1315
github.com/shogo82148/androidbinary v0.0.0-20180627093851-01c4bfa8b3b5
1416
golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect
1517
golang.org/x/tools v0.0.0-20181214171254-3c39ce7b6105 // indirect
1618
gopkg.in/cheggaaa/pb.v1 v1.0.27
19+
gopkg.in/resty.v1 v1.10.1
1720
gopkg.in/urfave/cli.v1 v1.20.0
1821
)

tunnel/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// REFERENCE
2+
// Go generate RSA https://gist.github.com/sdorra/1c95de8cb80da31610d2ad767cd6f251
3+
// Go Resty https://github.com/go-resty/resty
4+
package main
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
"time"
10+
11+
tunnel "github.com/labstack/tunnel-client"
12+
"github.com/qiniu/log"
13+
resty "gopkg.in/resty.v1"
14+
)
15+
16+
func main() {
17+
c := &tunnel.Configuration{
18+
Host: "labstack.me:22",
19+
RemoteHost: "0.0.0.0",
20+
RemotePort: 8000,
21+
Channel: make(chan int),
22+
}
23+
c.TargetHost = "10.246.46.160"
24+
c.TargetPort = 8080
25+
26+
// Ref: https://github.com/labstack/tunnel-client/blob/master/cmd/root.go
27+
res, err := resty.R().
28+
SetAuthToken("hello world").
29+
SetHeader("Content-Type", "application/json").
30+
SetHeader("User-Agent", "labstack/tunnel").
31+
Get("http://httpbin.org/get")
32+
if err != nil {
33+
log.Fatalf("request err: %v", err)
34+
} else if res.StatusCode() != http.StatusOK {
35+
log.Fatalf("request status code not 200, receive %d", res.StatusCode())
36+
}
37+
fmt.Printf("Response Body: %v", res.String())
38+
39+
CREATE:
40+
go tunnel.Create(c)
41+
event := <-c.Channel
42+
if event == tunnel.EventReconnect {
43+
log.Info("trying to reconnect")
44+
time.Sleep(1 * time.Second)
45+
goto CREATE
46+
}
47+
}

0 commit comments

Comments
 (0)