ing
This commit is contained in:
parent
9ea3676888
commit
b2bfe5bb2d
22
client/client.go
Normal file
22
client/client.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons_go/rpc"
|
||||
"git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
)
|
||||
|
||||
func NewClientHandler(addr string, codec protocol.ClientCodec, notifyRegistry rpc.Registry) ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.addr = addr
|
||||
ch.RPCRegistry = notifyRegistry
|
||||
ch.Codec = codec
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
client.ClientHandlers
|
||||
|
||||
addr string
|
||||
}
|
7
client/client_handler.go
Normal file
7
client/client_handler.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package client
|
||||
|
||||
import "git.loafle.net/commons_go/rpc/client"
|
||||
|
||||
type ClientHandler interface {
|
||||
client.ClientHandler
|
||||
}
|
2
client/client_handlers.go
Normal file
2
client/client_handlers.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package client
|
||||
|
9
internal/server/rpc/gateway_rpc_servlet_handler.go
Normal file
9
internal/server/rpc/gateway_rpc_servlet_handler.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons_go/rpc/gateway"
|
||||
)
|
||||
|
||||
type GatewayRPCServletHandler interface {
|
||||
gateway.ServletHandler
|
||||
}
|
36
internal/server/rpc/gateway_rpc_servlet_handlers.go
Normal file
36
internal/server/rpc/gateway_rpc_servlet_handlers.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/logging"
|
||||
crcwf "git.loafle.net/commons_go/rpc/connection/websocket/fasthttp"
|
||||
"git.loafle.net/commons_go/rpc/gateway"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
)
|
||||
|
||||
type GatewayRPCServletHandlers struct {
|
||||
gateway.ServletHandlers
|
||||
crcwf.ServletHandlers
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) Invoke(requestCodec protocol.RegistryCodec) (result interface{}, err error) {
|
||||
if !sh.RPCRegistry.HasMethod(requestCodec.Method()) {
|
||||
return nil, fmt.Errorf("RPC Servlet Handler: Method[%s] is not exist", requestCodec.Method())
|
||||
}
|
||||
|
||||
result, err = sh.RPCRegistry.Invoke(requestCodec)
|
||||
if nil != err {
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (sh *GatewayRPCServletHandlers) Validate() {
|
||||
sh.ServletHandlers.Validate()
|
||||
|
||||
if nil == sh.RPCRegistry {
|
||||
logging.Logger().Panic(fmt.Sprintf("RPC Servlet Handler: RPC Registry must be specified"))
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ import (
|
|||
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||
)
|
||||
|
||||
func New(sh ServerHandler) Server {
|
||||
s := cwf.New(sh)
|
||||
func New(serverCTX ServerContext, sh ServerHandler) Server {
|
||||
s := cwf.New(serverCTX, sh)
|
||||
|
||||
return s
|
||||
}
|
||||
|
|
21
server/server_context.go
Normal file
21
server/server_context.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
cuc "git.loafle.net/commons_go/util/context"
|
||||
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||
)
|
||||
|
||||
type ServerContext interface {
|
||||
cwf.ServerContext
|
||||
}
|
||||
|
||||
type serverContext struct {
|
||||
cwf.ServerContext
|
||||
}
|
||||
|
||||
func NewServerContext(parent cuc.Context) ServerContext {
|
||||
sCTX := &serverContext{}
|
||||
sCTX.ServerContext = cwf.NewServerContext(parent)
|
||||
|
||||
return sCTX
|
||||
}
|
|
@ -46,7 +46,7 @@ type ServerHandlers struct {
|
|||
|
||||
// Init invoked before the server is started
|
||||
// If you override ths method, must call
|
||||
func (sh *ServerHandlers) Init() error {
|
||||
func (sh *ServerHandlers) Init(serverCTX ServerContext) error {
|
||||
if err := sh.ServerHandlers.Init(); nil != err {
|
||||
return err
|
||||
}
|
||||
|
@ -56,11 +56,11 @@ func (sh *ServerHandlers) Init() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Listen() (net.Listener, error) {
|
||||
func (sh *ServerHandlers) Listen(serverCTX ServerContext) (net.Listener, error) {
|
||||
return net.Listen(config.Config.Server.Network, config.Config.Server.Addr)
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) OnStart() {
|
||||
func (sh *ServerHandlers) OnStart(serverCTX ServerContext) {
|
||||
sh.ServerHandlers.OnStart()
|
||||
|
||||
sh.redisSubscriber = oosr.New(redis.RedisPool.Get())
|
||||
|
@ -74,11 +74,11 @@ func (sh *ServerHandlers) OnStart() {
|
|||
}
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) OnError(ctx *fasthttp.RequestCtx, status int, reason error) {
|
||||
func (sh *ServerHandlers) OnError(serverCTX ServerContext, ctx *fasthttp.RequestCtx, status int, reason error) {
|
||||
sh.OnError(ctx, status, reason)
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) OnStop() {
|
||||
func (sh *ServerHandlers) OnStop(serverCTX ServerContext) {
|
||||
sh.redisSubscriber.Stop()
|
||||
|
||||
external.ExternalDestroy()
|
||||
|
|
Loading…
Reference in New Issue
Block a user