ing
This commit is contained in:
parent
900bf42638
commit
87d41a5c4f
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
10
client/client_handlers_unix.go
Normal file
10
client/client_handlers_unix.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
|
||||
func (ch *ClientHandlers) Connect() (io.ReadWriteCloser, error) {
|
||||
return net.Dial("unix", ch.addr)
|
||||
}
|
11
client/client_handlers_windows.go
Normal file
11
client/client_handlers_windows.go
Normal file
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user