Skip to content

Commit 452f72a

Browse files
committed
Using gommon/log
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 345755f commit 452f72a

File tree

93 files changed

+4132
-380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4132
-380
lines changed

Gopkg.lock

Lines changed: 41 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
# unused-packages = true
2626

2727

28+
[[constraint]]
29+
name = "github.com/labstack/gommon"
30+
version = "0.2.4"
31+
2832
[[constraint]]
2933
branch = "master"
3034
name = "github.com/mitchellh/go-homedir"
@@ -37,10 +41,10 @@
3741
name = "github.com/spf13/viper"
3842
version = "1.0.2"
3943

40-
[prune]
41-
go-tests = true
42-
unused-packages = true
43-
4444
[[constraint]]
4545
branch = "master"
4646
name = "golang.org/x/crypto"
47+
48+
[prune]
49+
go-tests = true
50+
unused-packages = true

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
VERSION = 0.1.2
1+
VERSION = 0.1.3
22

3-
build:
3+
publish:
44
git tag $(VERSION)
55
git push origin --tags
66
goreleaser --rm-dist
77

8-
.PHONY: build
8+
.PHONY: publish

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
Short: "Print the version of Tunnel",
1313
// Long: ``,
1414
Run: func(cmd *cobra.Command, args []string) {
15-
fmt.Println("0.1.2")
15+
fmt.Println("0.1.3")
1616
},
1717
}
1818
)

tunnel.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"bufio"
55
"fmt"
66
"io"
7-
"log"
87
"net"
98
"net/http"
109
"net/url"
1110
"os"
1211

12+
"github.com/labstack/gommon/log"
13+
1314
"golang.org/x/crypto/ssh"
1415
)
1516

@@ -20,6 +21,7 @@ type (
2021
RemotePort int
2122
TargetHost string
2223
TargetPort int
24+
HideBanner bool
2325
}
2426
)
2527

@@ -30,7 +32,7 @@ var (
3032
func (t *Tunnel) Create() {
3133
hostKey, _, _, _, err := ssh.ParseAuthorizedKey(hostBytes)
3234
if err != nil {
33-
log.Fatalf("Failed to parse host key %v\n", err)
35+
log.Fatalf("Failed to parse host key %v", err)
3436
}
3537
config := &ssh.ClientConfig{
3638
User: t.Protocol,
@@ -39,7 +41,9 @@ func (t *Tunnel) Create() {
3941
},
4042
HostKeyCallback: ssh.FixedHostKey(hostKey),
4143
BannerCallback: func(message string) error {
42-
fmt.Print(message)
44+
if !t.HideBanner {
45+
fmt.Print(message)
46+
}
4347
return nil
4448
},
4549
}
@@ -51,11 +55,11 @@ func (t *Tunnel) Create() {
5155
if proxy != "" {
5256
proxyURL, err := url.Parse(proxy)
5357
if err != nil {
54-
log.Fatalf("cannot open new session: %v\n", err)
58+
log.Fatalf("Cannot open new session %v", err)
5559
}
5660
tcp, err := net.Dial("tcp", proxyURL.Hostname())
5761
if err != nil {
58-
log.Fatalf("cannot open new session: %v\n", err)
62+
log.Fatalf("Cannot open new session %v", err)
5963
}
6064
connReq := &http.Request{
6165
Method: "CONNECT",
@@ -71,27 +75,27 @@ func (t *Tunnel) Create() {
7175
connReq.Write(tcp)
7276
resp, err := http.ReadResponse(bufio.NewReader(tcp), connReq)
7377
if err != nil {
74-
log.Fatalf("cannot open new session: %v\n", err)
78+
log.Fatalf("Cannot open new session %v", err)
7579
}
7680
defer resp.Body.Close()
7781

7882
c, chans, reqs, err := ssh.NewClientConn(tcp, hostport, config)
7983
if err != nil {
80-
log.Fatalf("cannot open new session: %v\n", err)
84+
log.Fatalf("Cannot open new session %v", err)
8185
}
8286
client = ssh.NewClient(c, chans, reqs)
8387
} else {
8488
client, err = ssh.Dial("tcp", hostport, config)
8589
}
8690
if err != nil {
87-
log.Fatalf("Failed to connect %v\n", err)
91+
log.Fatalf("Failed to connect %v", err)
8892
}
8993
defer client.Close()
9094

9195
// Session
9296
sess, err := client.NewSession()
9397
if err != nil {
94-
log.Fatalf("Failed to create session %v\n", err)
98+
log.Fatalf("Failed to create session %v", err)
9599
}
96100
defer sess.Close()
97101
r, err := sess.StdoutPipe()
@@ -109,15 +113,15 @@ func (t *Tunnel) Create() {
109113
// Remote listener
110114
ln, err := client.Listen("tcp", fmt.Sprintf("%s:%d", t.RemoteHost, t.RemotePort))
111115
if err != nil {
112-
log.Fatalf("Failed to listen on remote host %v\n", err)
116+
log.Fatalf("Failed to listen on remote host %v", err)
113117
}
114118
defer ln.Close()
115119

116120
for {
117121
// Handle inbound connection
118122
in, err := ln.Accept()
119123
if err != nil {
120-
log.Printf("Failed to accept connection %v\n", err)
124+
log.Printf("Failed to accept connection %v", err)
121125
break
122126
}
123127

@@ -127,7 +131,7 @@ func (t *Tunnel) Create() {
127131
// Target connection
128132
out, err := net.Dial("tcp", fmt.Sprintf("%s:%d", t.TargetHost, t.TargetPort))
129133
if err != nil {
130-
log.Printf("%v\n", err)
134+
log.Printf("Failed to connect to target %v", err)
131135
return
132136
}
133137
defer out.Close()
@@ -144,7 +148,7 @@ func (t *Tunnel) Create() {
144148
// Handle error
145149
err = <-errCh
146150
if err != nil && err != io.EOF {
147-
log.Printf("Failed to copy %v\n", err)
151+
log.Printf("Failed to copy %v", err)
148152
}
149153
}(in)
150154
}

vendor/github.com/hashicorp/hcl/hcl/parser/parser.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)