Browse Source

use conventional command and package paths

pull/2/head
AJ ONeal 3 years ago
parent
commit
d4eb17ea44
  1. 4
      README.md
  2. 16
      build-all.sh
  3. 8
      cmd/sclient/main.go
  4. 10
      sclient.go

4
README.md

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

16
build-all.sh

@ -1,29 +1,31 @@
#GOOS=windows GOARCH=amd64 go install
go tool dist list
gocmd=cmd/sclient/main.go
golib=""
echo ""
echo ""
echo "Windows amd64"
GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe sclient*.go
GOOS=windows GOARCH=amd64 go build -o dist/windows/amd64/sclient.exe $gocmd $golib
echo "Windows 386"
GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe sclient*.go
GOOS=windows GOARCH=386 go build -o dist/windows/386/sclient.exe $gocmd $golib
echo ""
echo "Darwin (macOS) amd64"
GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient sclient*.go
GOOS=darwin GOARCH=amd64 go build -o dist/darwin/amd64/sclient $gocmd $golib
echo ""
echo "Linux amd64"
GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient sclient*.go
GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/sclient $gocmd $golib
echo "Linux 386"
echo ""
GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient sclient*.go
GOOS=linux GOARCH=386 go build -o dist/linux/386/sclient $gocmd $golib
echo "RPi 3 B+ ARMv7"
GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient sclient*.go
GOOS=linux GOARCH=arm GOARM=7 go build -o dist/linux/armv7/sclient $gocmd $golib
echo "RPi Zero ARMv5"
GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient sclient*.go
GOOS=linux GOARCH=arm GOARM=5 go build -o dist/linux/armv5/sclient $gocmd $golib
echo ""
echo ""

8
sclient-cli.go → cmd/sclient/main.go

@ -6,10 +6,12 @@ import (
"os"
"strconv"
"strings"
sclient "git.coolaj86.com/sclient.go"
)
func usage() {
fmt.Fprintf(os.Stderr, "\nusage: go run sclient*.go <remote> <local>\n"+
fmt.Fprintf(os.Stderr, "\nusage: sclient <remote> <local>\n"+
"\n"+
" ex: sclient example.com 3000\n"+
" (sclient example.com:443 localhost:3000)\n"+
@ -39,7 +41,7 @@ func main() {
}
}
opts := &SclientOpts{}
opts := &sclient.PipeOpts{}
opts.RemotePort = 443
opts.LocalAddress = "localhost"
opts.InsecureSkipVerify = *insecure
@ -85,7 +87,7 @@ func main() {
}
}
sclient := &Sclient{}
sclient := &sclient.Tun{}
err := sclient.DialAndListen(opts)
if nil != err {
fmt.Fprintf(os.Stderr, "%s\n", err)

10
sclient.go

@ -1,4 +1,4 @@
package main
package sclient
import (
"crypto/tls"
@ -40,7 +40,7 @@ type Rwc interface {
RemoteAddr() net.Addr
}
type SclientOpts struct {
type PipeOpts struct {
RemoteAddress string
RemotePort int
LocalAddress string
@ -48,7 +48,7 @@ type SclientOpts struct {
InsecureSkipVerify bool
}
type Sclient struct{}
type Tun struct{}
func pipe(r Rwc, w Rwc, t string) {
buffer := make([]byte, 2048)
@ -86,7 +86,7 @@ func pipe(r Rwc, w Rwc, t string) {
}
}
func handleConnection(remote string, conn Rwc, opts *SclientOpts) {
func handleConnection(remote string, conn Rwc, opts *PipeOpts) {
sclient, err := tls.Dial("tcp", remote,
&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify})
@ -108,7 +108,7 @@ func handleConnection(remote string, conn Rwc, opts *SclientOpts) {
pipe(sclient, conn, "remote")
}
func (*Sclient) DialAndListen(opts *SclientOpts) error {
func (*Tun) DialAndListen(opts *PipeOpts) error {
remote := opts.RemoteAddress + ":" + strconv.Itoa(opts.RemotePort)
conn, err := tls.Dial("tcp", remote,
&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify})

Loading…
Cancel
Save