From 187ef708f6d07ee1ea89f2bc0637e543327b63da Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 26 Oct 2017 21:30:55 +0900 Subject: [PATCH] ing --- glide.yaml | 1 + ipc/ipc.go | 9 +++++++++ ipc/ipc_unix.go | 16 ++++++++++++++++ ipc/ipc_windows.go | 13 +++++++++++++ tcp/tcp.go | 16 ++++++++++++++++ tcp_tls/tcp_tls.go | 19 +++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 ipc/ipc.go create mode 100644 ipc/ipc_unix.go create mode 100644 ipc/ipc_windows.go create mode 100644 tcp/tcp.go create mode 100644 tcp_tls/tcp_tls.go diff --git a/glide.yaml b/glide.yaml index 2098be0..c206e6e 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,3 +1,4 @@ package: git.loafle.net/commons_go/server import: - package: git.loafle.net/commons_go/logging +- package: gopkg.in/natefinch/npipe.v2 diff --git a/ipc/ipc.go b/ipc/ipc.go new file mode 100644 index 0000000..1e4c03e --- /dev/null +++ b/ipc/ipc.go @@ -0,0 +1,9 @@ +package ipc + +import "git.loafle.net/commons_go/server" + +type ServerHandlers struct { + server.ServerHandlers + + path string +} diff --git a/ipc/ipc_unix.go b/ipc/ipc_unix.go new file mode 100644 index 0000000..57e7eed --- /dev/null +++ b/ipc/ipc_unix.go @@ -0,0 +1,16 @@ +package ipc + +import ( + "net" + "os" + "path/filepath" +) + +func (sh *ServerHandlers) Listen() (net.Listener, error) { + sh.path = filepath.Join(os.TempDir(), sh.Addr) + if err := os.Remove(sh.path); nil != err { + return nil, err + } + + return net.ListenUnix("unix", &net.UnixAddr{Name: sh.path, Net: "unix"}) +} diff --git a/ipc/ipc_windows.go b/ipc/ipc_windows.go new file mode 100644 index 0000000..0674028 --- /dev/null +++ b/ipc/ipc_windows.go @@ -0,0 +1,13 @@ +package ipc + +import ( + "net" + + "gopkg.in/natefinch/npipe.v2" +) + +func (sh *ServerHandlers) Listen() (net.Listener, error) { + sh.path = `\\.\pipe\` + sh.Addr + + return npipe.Listen(s.path) +} diff --git a/tcp/tcp.go b/tcp/tcp.go new file mode 100644 index 0000000..31ff142 --- /dev/null +++ b/tcp/tcp.go @@ -0,0 +1,16 @@ +package tcp + +import ( + "net" + + "git.loafle.net/commons_go/server" +) + +type ServerHandlers struct { + server.ServerHandlers +} + +func (sh *ServerHandlers) Listen() (net.Listener, error) { + + return net.Listen("tcp", sh.Addr) +} diff --git a/tcp_tls/tcp_tls.go b/tcp_tls/tcp_tls.go new file mode 100644 index 0000000..a34c163 --- /dev/null +++ b/tcp_tls/tcp_tls.go @@ -0,0 +1,19 @@ +package tcp_tls + +import ( + "crypto/tls" + "net" + + "git.loafle.net/commons_go/server" +) + +type ServerHandlers struct { + server.ServerHandlers + + tlsConfig *tls.Config +} + +func (sh *ServerHandlers) Listen() (net.Listener, error) { + + return tls.Listen("tcp", sh.Addr, sh.tlsConfig) +}