diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-11 13:48:07 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-11 13:48:07 -0400 |
| commit | cf59ee3ec4b5233910de4f67b38fab3e4df7d5fb (patch) | |
| tree | 2f00341969c54357b82f8ff4d9bf99a187dd977f /main.go | |
| parent | 93610fb8d1640763f0cd4ae5d465d8377696c273 (diff) | |
| download | hose-cf59ee3ec4b5233910de4f67b38fab3e4df7d5fb.zip | |
logf()
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -31,7 +31,7 @@ func main() { eprintf("%v\n", err) } } else { - fmt.Println(usage) + logf("%s\n", usage) flag.Usage() os.Exit(1) } @@ -45,37 +45,41 @@ func recv() error { return err } defer ln.Close() - fmt.Fprintf(os.Stderr, "listening on %s\n", laddr) + logf("listening on %s\n", laddr) conn, err := ln.Accept() if err != nil { return err } defer conn.Close() - fmt.Fprintf(os.Stderr, "accepted connection from %s\n", conn.RemoteAddr()) + logf("accepted connection from %s\n", conn.RemoteAddr()) n, err := io.Copy(os.Stdout, conn) - fmt.Fprintf(os.Stderr, "received %.2f\n", units.Bytes(n)*units.B) + logf("received %.2f\n", units.Bytes(n)*units.B) return err } // send pipes data from stdin to the remote host. func send(rhost string) error { raddr := net.JoinHostPort(rhost, port) - fmt.Fprintf(os.Stderr, "connecting to %s...\n", raddr) + logf("connecting to %s...\n", raddr) conn, err := net.Dial(network, raddr) if err != nil { return err } defer conn.Close() - fmt.Fprintf(os.Stderr, "connected to %s\n", raddr) + logf("connected to %s\n", raddr) n, err := io.Copy(conn, os.Stdin) - fmt.Fprintf(os.Stderr, "sent %.2f\n", units.Bytes(n)*units.B) + logf("sent %.2f\n", units.Bytes(n)*units.B) return err } func eprintf(format string, a ...any) { - fmt.Fprintf(os.Stderr, format, a...) + logf(format, a...) os.Exit(1) } + +func logf(format string, a ...any) { + fmt.Fprintf(os.Stderr, format, a...) +} |