summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorDmitry Patsura <[email protected]>2019-06-13 17:43:39 +0300
committerDmitry Patsura <[email protected]>2019-06-13 20:00:56 +0300
commit82cfc4f8f89252083aa09e8370b9605d38808b70 (patch)
treea5846b0ca28248e895148aa866bea416e26fb69c /util
parent27e8cb3c4086012968b586fcbd5fd40737be2510 (diff)
Feature: Extract code to util.CreateListener
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