summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/network.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/util/network.go b/util/network.go
new file mode 100644
index 00000000..1ceb95b0
--- /dev/null
+++ b/util/network.go
@@ -0,0 +1,21 @@
+package util
+
+import (
+ "net"
+ "strings"
+ "syscall"
+ "errors"
+)
+
+func CreateListener(address string) (net.Listener, error) {
+ dsn := strings.Split(address, "://")
+ if len(dsn) != 2 {
+ return nil, errors.New("invalid socket DSN (tcp://:6001, unix://file.sock)")
+ }
+
+ if dsn[0] == "unix" {
+ syscall.Unlink(dsn[1])
+ }
+
+ return net.Listen(dsn[0], dsn[1])
+} \ No newline at end of file