This commit is contained in:
crusader 2017-10-26 21:30:55 +09:00
parent 2da8c2ca47
commit 187ef708f6
6 changed files with 74 additions and 0 deletions

View File

@ -1,3 +1,4 @@
package: git.loafle.net/commons_go/server package: git.loafle.net/commons_go/server
import: import:
- package: git.loafle.net/commons_go/logging - package: git.loafle.net/commons_go/logging
- package: gopkg.in/natefinch/npipe.v2

9
ipc/ipc.go Normal file
View File

@ -0,0 +1,9 @@
package ipc
import "git.loafle.net/commons_go/server"
type ServerHandlers struct {
server.ServerHandlers
path string
}

16
ipc/ipc_unix.go Normal file
View File

@ -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"})
}

13
ipc/ipc_windows.go Normal file
View File

@ -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)
}

16
tcp/tcp.go Normal file
View File

@ -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)
}

19
tcp_tls/tcp_tls.go Normal file
View File

@ -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)
}