1
1
mirror of https://github.com/therootcompany/sclient synced 2025-08-18 16:16:31 +00:00

ref(lint): swap yoda conditions, make intentionally ignored errors explicit

This commit is contained in:
AJ ONeal 2025-08-06 15:37:24 -06:00
parent 3a2792dcd1
commit d806c1853c
No known key found for this signature in database
GPG Key ID: 9334E610B1ED6FBF
2 changed files with 18 additions and 19 deletions

View File

@ -68,9 +68,9 @@ func main() {
localstr := flag.Arg(1) localstr := flag.Arg(1)
i := flag.NArg() i := flag.NArg()
if 2 != i { if i != 2 {
// We may omit the second argument if we're going straight to stdin // We may omit the second argument if we're going straight to stdin
if stat, _ := os.Stdin.Stat(); 1 == i && (stat.Mode()&os.ModeCharDevice) == 0 { if stat, _ := os.Stdin.Stat(); i == 1 && (stat.Mode()&os.ModeCharDevice) == 0 {
localstr = "|" localstr = "|"
} else { } else {
usage() usage()
@ -89,20 +89,20 @@ func main() {
remote := strings.Split(remotestr, ":") remote := strings.Split(remotestr, ":")
//remoteAddr, remotePort, err := net.SplitHostPort(remotestr) //remoteAddr, remotePort, err := net.SplitHostPort(remotestr)
if 2 == len(remote) { if len(remote) == 2 {
rport, err := strconv.Atoi(remote[1]) rport, err := strconv.Atoi(remote[1])
if nil != err { if nil != err {
usage() usage()
os.Exit(0) os.Exit(0)
} }
sclient.RemotePort = rport sclient.RemotePort = rport
} else if 1 != len(remote) { } else if len(remote) != 1 {
usage() usage()
os.Exit(0) os.Exit(0)
} }
sclient.RemoteAddress = remote[0] sclient.RemoteAddress = remote[0]
if "-" == localstr || "|" == localstr { if localstr == "-" || localstr == "|" {
// User may specify stdin/stdout instead of net // User may specify stdin/stdout instead of net
sclient.LocalAddress = localstr sclient.LocalAddress = localstr
sclient.LocalPort = -1 sclient.LocalPort = -1
@ -110,7 +110,7 @@ func main() {
// Test that argument is a local address // Test that argument is a local address
local := strings.Split(localstr, ":") local := strings.Split(localstr, ":")
if 1 == len(local) { if len(local) == 1 {
lport, err := strconv.Atoi(local[0]) lport, err := strconv.Atoi(local[0])
if nil != err { if nil != err {
usage() usage()
@ -144,9 +144,8 @@ func parseOptionList(optionList string) []string {
return nil return nil
} }
options := []string{}
optionList = strings.ReplaceAll(optionList, ",", " ") optionList = strings.ReplaceAll(optionList, ",", " ")
options = strings.Fields(optionList) options := strings.Fields(optionList)
return options return options
} }

View File

@ -36,14 +36,14 @@ func (t *Tunnel) DialAndListen() error {
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "[warn] '%s' may not be accepting connections: %s\n", remote, err) fmt.Fprintf(os.Stderr, "[warn] '%s' may not be accepting connections: %s\n", remote, err)
} else { } else {
conn.Close() _ = conn.Close()
} }
// use stdin/stdout // use stdin/stdout
if "-" == t.LocalAddress || "|" == t.LocalAddress { if t.LocalAddress == "-" || t.LocalAddress == "|" {
var name string var name string
network := "stdio" network := "stdio"
if "|" == t.LocalAddress { if t.LocalAddress == "|" {
name = "pipe" name = "pipe"
} else { } else {
name = "stdin" name = "stdin"
@ -61,7 +61,7 @@ func (t *Tunnel) DialAndListen() error {
} }
if !t.Silent { if !t.Silent {
fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n", _, _ = fmt.Fprintf(os.Stdout, "[listening] %s:%d <= %s:%d\n",
t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort) t.RemoteAddress, t.RemotePort, t.LocalAddress, t.LocalPort)
} }
@ -117,11 +117,11 @@ func pipe(r netReadWriteCloser, w netReadWriteCloser, t string) {
if io.EOF != err { if io.EOF != err {
fmt.Fprintf(os.Stderr, "[read error] (%s:%d) %s\n", t, count, err) fmt.Fprintf(os.Stderr, "[read error] (%s:%d) %s\n", t, count, err)
} }
r.Close() _ = r.Close()
//w.Close() //w.Close()
done = true done = true
} }
if 0 == count { if count == 0 {
break break
} }
_, err = w.Write(buffer[:count]) _, err = w.Write(buffer[:count])
@ -131,7 +131,7 @@ func pipe(r netReadWriteCloser, w netReadWriteCloser, t string) {
fmt.Fprintf(os.Stderr, "[write error] (%s) %s\n", t, err) fmt.Fprintf(os.Stderr, "[write error] (%s) %s\n", t, err)
} }
// TODO handle error closing? // TODO handle error closing?
r.Close() _ = r.Close()
//w.Close() //w.Close()
done = true done = true
} }
@ -151,16 +151,16 @@ func (t *Tunnel) handleConnection(remote string, conn netReadWriteCloser) {
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "[error] (remote) %s\n", err) fmt.Fprintf(os.Stderr, "[error] (remote) %s\n", err)
conn.Close() _ = conn.Close()
return return
} }
if !t.Silent { if !t.Silent {
if "stdio" == conn.RemoteAddr().Network() { if conn.RemoteAddr().Network() == "stdio" {
fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n", _, _ = fmt.Fprintf(os.Stdout, "(connected to %s:%d and reading from %s)\n",
t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String()) t.RemoteAddress, t.RemotePort, conn.RemoteAddr().String())
} else { } else {
fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n", _, _ = fmt.Fprintf(os.Stdout, "[connect] %s => %s:%d\n",
strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort) strings.Replace(conn.RemoteAddr().String(), "[::1]:", "localhost:", 1), t.RemoteAddress, t.RemotePort)
} }
} }