diff --git a/client/client.go b/client/client.go index 4978c46..6751b83 100644 --- a/client/client.go +++ b/client/client.go @@ -2,33 +2,14 @@ package client import ( "git.loafle.net/commons_go/rpc" - "git.loafle.net/commons_go/server" - rpcClient "git.loafle.net/overflow/overflow_discovery/client/rpc" + "git.loafle.net/commons_go/rpc/client" ) -func New(addr string, registry rpc.Registry) Client { +func New(addr string, registry rpc.Registry) client.Client { ch := NewClientHandler(addr, registry) - c := &client{} - c.Client = server.NewClient(ch) - c.ch = ch + c := client.New(ch) return c } - -type Client interface { - server.Client - - RPC() rpcClient.Client -} - -type client struct { - server.Client - - ch *ClientHandlers -} - -func (c *client) RPC() rpcClient.Client { - return c.ch.RPCClient -} diff --git a/client/client_handlers.go b/client/client_handlers.go index 9886d64..c366125 100644 --- a/client/client_handlers.go +++ b/client/client_handlers.go @@ -1,51 +1,20 @@ package client import ( - "io" - "log" - "git.loafle.net/commons_go/rpc" - "git.loafle.net/commons_go/server/ipc" - rpcClient "git.loafle.net/overflow/overflow_discovery/client/rpc" + "git.loafle.net/commons_go/rpc/client" ) func NewClientHandler(addr string, registry rpc.Registry) *ClientHandlers { ch := &ClientHandlers{} - ch.Addr = addr - ch.RPCClient = rpcClient.New(registry) + ch.addr = addr + ch.RPCRegistry = registry return ch } type ClientHandlers struct { - ipc.ClientHandlers - - RPCClient rpcClient.Client -} - -func (ch *ClientHandlers) OnStart() { - // no op - log.Printf("discovery.ClientHandlers.OnStart") -} - -func (ch *ClientHandlers) OnStop() { - // no op -} - -func (ch *ClientHandlers) OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error { - return nil -} - -func (ch *ClientHandlers) Handle(rwc io.ReadWriteCloser, stopChan chan struct{}) { - log.Printf("discovery.ClientHandlers.Handle") - - ch.RPCClient.Start(rwc) - - select { - case <-stopChan: - rwc.Close() - return - default: - } + client.ClientHandlers + addr string } diff --git a/client/client_handlers_unix.go b/client/client_handlers_unix.go new file mode 100644 index 0000000..088ba3b --- /dev/null +++ b/client/client_handlers_unix.go @@ -0,0 +1,10 @@ +package client + +import ( + "io" + "net" +) + +func (ch *ClientHandlers) Connect() (io.ReadWriteCloser, error) { + return net.Dial("unix", ch.addr) +} diff --git a/client/client_handlers_windows.go b/client/client_handlers_windows.go new file mode 100644 index 0000000..4e03da5 --- /dev/null +++ b/client/client_handlers_windows.go @@ -0,0 +1,11 @@ +package client + +import ( + "io" + + "gopkg.in/natefinch/npipe.v2" +) + +func (ch *ClientHandlers) Connect() (io.ReadWriteCloser, error) { + return npipe.Dial(ch.addr) +} diff --git a/client/rpc/client.go b/client/rpc/client.go deleted file mode 100644 index 69a70da..0000000 --- a/client/rpc/client.go +++ /dev/null @@ -1,19 +0,0 @@ -package rpc - -import ( - "git.loafle.net/commons_go/rpc" - rpcClient "git.loafle.net/commons_go/rpc/client" -) - -func New(registry rpc.Registry) Client { - - ch := NewClientHandler(registry) - - c := rpcClient.New(ch) - - return c -} - -type Client interface { - rpcClient.Client -} diff --git a/client/rpc/client_handlers.go b/client/rpc/client_handlers.go deleted file mode 100644 index 04f7bbc..0000000 --- a/client/rpc/client_handlers.go +++ /dev/null @@ -1,28 +0,0 @@ -package rpc - -import ( - "git.loafle.net/commons_go/rpc" - rpcClient "git.loafle.net/commons_go/rpc/client" - "git.loafle.net/commons_go/rpc/protocol/json" -) - -func NewClientHandler(registry rpc.Registry) *ClientHandlers { - ch := &ClientHandlers{} - ch.ContentType = "json" - ch.Codec = json.NewClientCodec() - ch.RPCRegistry = registry - - return ch -} - -type ClientHandlers struct { - rpcClient.ClientHandlers -} - -func (ch *ClientHandlers) OnStart() { - // no op -} - -func (ch *ClientHandlers) OnStop() { - // no op -}