diff options
Diffstat (limited to 'util/network_windows.go')
-rw-r--r-- | util/network_windows.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/util/network_windows.go b/util/network_windows.go new file mode 100644 index 00000000..e5bc67c8 --- /dev/null +++ b/util/network_windows.go @@ -0,0 +1,33 @@ +// +build windows + +package util + +import ( + "errors" + "fmt" + "net" + "os" + "strings" + "syscall" +) + +// CreateListener crates socket listener based on DSN definition. +func CreateListener(address string) (net.Listener, error) { + dsn := strings.Split(address, "://") + if len(dsn) != 2 { + return nil, errors.New("invalid DSN (tcp://:6001, unix://file.sock)") + } + + if dsn[0] != "unix" && dsn[0] != "tcp" { + return nil, errors.New("invalid Protocol (tcp://:6001, unix://file.sock)") + } + + if dsn[0] == "unix" && fileExists(dsn[1]) { + err := syscall.Unlink(dsn[1]) + if err != nil { + return nil, fmt.Errorf("error during the unlink syscall: error %v", err) + } + } + + return net.Listen(dsn[0], dsn[1]) +}
\ No newline at end of file |