aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-10 00:39:16 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-10 00:39:37 +0100
commit03f8544691a8de9f77a803fd8cd2eeadb919ec03 (patch)
tree4d3431d678b892cb057af72a982ac73d313d60f9 /go
Genesis commit
Diffstat (limited to 'go')
-rw-r--r--go/read-unix-sock/read-unix-sock.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/go/read-unix-sock/read-unix-sock.go b/go/read-unix-sock/read-unix-sock.go
new file mode 100644
index 0000000..2b09126
--- /dev/null
+++ b/go/read-unix-sock/read-unix-sock.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "io/fs"
+ "net"
+ "os"
+)
+
+func main() {
+ info, _ := os.Stat(os.Args[1])
+ if info.Mode().Type() != fs.ModeSocket {
+ fmt.Fprintln(os.Stderr, "File is not a socket")
+ os.Exit(1)
+ }
+
+ c, _ := net.Dial("unix", os.Args[1])
+ defer c.Close()
+
+ buf := make([]byte, 1024)
+ for {
+ n, err := c.Read(buf)
+ if errors.Is(err, io.EOF) {
+ return
+ }
+ fmt.Print(string(buf[:n]))
+ }
+}