This commit is contained in:
crusader
2017-12-04 20:59:11 +09:00
commit 8d60284f54
26 changed files with 576 additions and 0 deletions

15
client/client.go Normal file
View File

@@ -0,0 +1,15 @@
package client
import (
crc "git.loafle.net/commons_go/rpc/client"
crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket"
csc "git.loafle.net/commons_go/server/client"
)
func New(clientHandler ClientHandler, socketBuilder csc.SocketBuilder) crc.Client {
cRWCHandler := crcrs.New(socketBuilder)
c := crc.New(clientHandler, cRWCHandler)
return c
}

7
client/client_handler.go Normal file
View File

@@ -0,0 +1,7 @@
package client
import "git.loafle.net/commons_go/rpc/client"
type ClientHandler interface {
client.ClientHandler
}

19
client/client_handlers.go Normal file
View File

@@ -0,0 +1,19 @@
package client
import (
crc "git.loafle.net/commons_go/rpc/client"
"git.loafle.net/commons_go/rpc/protocol/json"
crr "git.loafle.net/commons_go/rpc/registry"
)
func NewClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler {
ch := &ClientHandlers{}
ch.RPCInvoker = rpcInvoker
ch.Codec = json.NewClientCodec()
return ch
}
type ClientHandlers struct {
crc.ClientHandlers
}

17
client/socket_builders.go Normal file
View File

@@ -0,0 +1,17 @@
package client
import (
csc "git.loafle.net/commons_go/server/client"
)
func NewSocketBuilder(address string) csc.SocketBuilder {
return newSocketBuilder(address)
}
type SocketBuilders struct {
csc.SocketBuilders
}
func (sb *SocketBuilders) SocketHandler() csc.SocketHandler {
return NewSocketHandler()
}

View File

@@ -0,0 +1,13 @@
package client
import (
csc "git.loafle.net/commons_go/server/client"
)
func newSocketBuilder(address string) csc.SocketBuilder {
sb := &SocketBuilders{}
sb.Network = "unix"
sb.Address = address
return sb
}

View File

@@ -0,0 +1,23 @@
package client
import (
"net"
csc "git.loafle.net/commons_go/server/client"
"gopkg.in/natefinch/npipe.v2"
)
func newSocketBuilder(address string) csc.SocketBuilder {
sb := &SocketBuilders{}
sb.Network = "pipe"
sb.Address = address
return sb
}
func (sb *SocketBuilders) Dial(network, address string) (net.Conn, error) {
if 0 == sb.HandshakeTimeout {
return npipe.Dial(`\\.\pipe\` + address)
}
return npipe.DialTimeout(`\\.\pipe\`+address, sb.HandshakeTimeout)
}

28
client/socket_handlers.go Normal file
View File

@@ -0,0 +1,28 @@
package client
import (
"log"
"net"
csc "git.loafle.net/commons_go/server/client"
)
type SocketHandlers struct {
csc.SocketHandlers
}
func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) {
log.Printf("OnConnect res: %v \n", conn)
}
func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) {
log.Printf("OnDisconnect \n")
}
func (sh *SocketHandlers) Validate() {
sh.SocketHandlers.Validate()
}
func NewSocketHandler() csc.SocketHandler {
return &SocketHandlers{}
}