Browse Source

use conventional command and package paths

AJ ONeal 4 months ago
parent
commit
d4eb17ea44
4 changed files with 21 additions and 17 deletions
  1. 2
    2
      README.md
  2. 9
    7
      build-all.sh
  3. 5
    3
      cmd/sclient/main.go
  4. 5
    5
      sclient.go

+ 2
- 2
README.md View File

@@ -52,12 +52,12 @@ For the moment you'll have to install go and compile `sclient` yourself:
52 52
 ```bash
53 53
 git clone https://git.coolaj86.com/coolaj86/sclient.go.git
54 54
 pushd sclient.go
55
-go build -o dist/sclient sclient*.go
55
+go build -o dist/sclient cmd/sclient/main.go
56 56
 rsync -av dist/sclient /usr/local/bin/sclient
57 57
 ```
58 58
 
59 59
 ```bash
60
-go run sclient*.go example.com:443 localhost:3000
60
+go run cmd/sclient/main.go example.com:443 localhost:3000
61 61
 ```
62 62
 
63 63
 Usage

+ 9
- 7
build-all.sh View File

@@ -1,29 +1,31 @@
1 1
 #GOOS=windows GOARCH=amd64 go install
2 2
 go tool dist list
3 3
 
4
+gocmd=cmd/sclient/main.go
5
+golib=""
4 6
 echo ""
5 7
 
6 8
 echo ""
7 9
 echo "Windows amd64"
8
-GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe sclient*.go
10
+GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe $gocmd $golib
9 11
 echo "Windows 386"
10
-GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe sclient*.go
12
+GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe $gocmd $golib
11 13
 
12 14
 echo ""
13 15
 echo "Darwin (macOS) amd64"
14
-GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient sclient*.go
16
+GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient $gocmd $golib
15 17
 
16 18
 echo ""
17 19
 echo "Linux amd64"
18
-GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient sclient*.go
20
+GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient $gocmd $golib
19 21
 echo "Linux 386"
20 22
 
21 23
 echo ""
22
-GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient sclient*.go
24
+GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient $gocmd $golib
23 25
 echo "RPi 3 B+ ARMv7"
24
-GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient sclient*.go
26
+GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient $gocmd $golib
25 27
 echo "RPi Zero ARMv5"
26
-GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient sclient*.go
28
+GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient $gocmd $golib
27 29
 
28 30
 echo ""
29 31
 echo ""

sclient-cli.go → cmd/sclient/main.go View File

@@ -6,10 +6,12 @@ import (
6 6
 	"os"
7 7
 	"strconv"
8 8
 	"strings"
9
+
10
+	sclient "git.coolaj86.com/sclient.go"
9 11
 )
10 12
 
11 13
 func usage() {
12
-	fmt.Fprintf(os.Stderr, "\nusage: go run sclient*.go <remote> <local>\n"+
14
+	fmt.Fprintf(os.Stderr, "\nusage: sclient <remote> <local>\n"+
13 15
 		"\n"+
14 16
 		"   ex: sclient example.com 3000\n"+
15 17
 		"      (sclient example.com:443 localhost:3000)\n"+
@@ -39,7 +41,7 @@ func main() {
39 41
 		}
40 42
 	}
41 43
 
42
-	opts := &SclientOpts{}
44
+	opts := &sclient.PipeOpts{}
43 45
 	opts.RemotePort = 443
44 46
 	opts.LocalAddress = "localhost"
45 47
 	opts.InsecureSkipVerify = *insecure
@@ -85,7 +87,7 @@ func main() {
85 87
 		}
86 88
 	}
87 89
 
88
-	sclient := &Sclient{}
90
+	sclient := &sclient.Tun{}
89 91
 	err := sclient.DialAndListen(opts)
90 92
 	if nil != err {
91 93
 		fmt.Fprintf(os.Stderr, "%s\n", err)

+ 5
- 5
sclient.go View File

@@ -1,4 +1,4 @@
1
-package main
1
+package sclient
2 2
 
3 3
 import (
4 4
 	"crypto/tls"
@@ -40,7 +40,7 @@ type Rwc interface {
40 40
 	RemoteAddr() net.Addr
41 41
 }
42 42
 
43
-type SclientOpts struct {
43
+type PipeOpts struct {
44 44
 	RemoteAddress      string
45 45
 	RemotePort         int
46 46
 	LocalAddress       string
@@ -48,7 +48,7 @@ type SclientOpts struct {
48 48
 	InsecureSkipVerify bool
49 49
 }
50 50
 
51
-type Sclient struct{}
51
+type Tun struct{}
52 52
 
53 53
 func pipe(r Rwc, w Rwc, t string) {
54 54
 	buffer := make([]byte, 2048)
@@ -86,7 +86,7 @@ func pipe(r Rwc, w Rwc, t string) {
86 86
 	}
87 87
 }
88 88
 
89
-func handleConnection(remote string, conn Rwc, opts *SclientOpts) {
89
+func handleConnection(remote string, conn Rwc, opts *PipeOpts) {
90 90
 	sclient, err := tls.Dial("tcp", remote,
91 91
 		&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify})
92 92
 
@@ -108,7 +108,7 @@ func handleConnection(remote string, conn Rwc, opts *SclientOpts) {
108 108
 	pipe(sclient, conn, "remote")
109 109
 }
110 110
 
111
-func (*Sclient) DialAndListen(opts *SclientOpts) error {
111
+func (*Tun) DialAndListen(opts *PipeOpts) error {
112 112
 	remote := opts.RemoteAddress + ":" + strconv.Itoa(opts.RemotePort)
113 113
 	conn, err := tls.Dial("tcp", remote,
114 114
 		&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify})