rpc/server/rwc/socket/servlet_rwc_handlers.go

52 lines
1.3 KiB
Go
Raw Normal View History

2017-11-29 09:55:24 +00:00
package socket
import (
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol"
"git.loafle.net/commons_go/server"
)
2017-11-29 10:02:33 +00:00
func New() rpc.ServletReadWriteCloseHandler {
return &ServletReadWriteCloseHandlers{}
2017-11-29 09:55:24 +00:00
}
2017-11-29 10:02:33 +00:00
type ServletReadWriteCloseHandlers struct {
rpc.ServletReadWriteCloseHandlers
}
2018-03-23 09:45:53 +00:00
func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
2017-11-29 09:55:24 +00:00
soc := conn.(server.Socket)
2018-03-22 13:35:08 +00:00
2018-03-23 09:45:53 +00:00
return codec.NewRequest(soc)
2017-11-29 09:55:24 +00:00
}
2017-11-29 10:02:33 +00:00
func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, reqCodec protocol.ServerRequestCodec, result interface{}, err error) error {
2018-03-22 13:35:08 +00:00
var (
wErr error
)
2017-11-29 09:55:24 +00:00
soc := conn.(server.Socket)
if nil != err {
2018-03-22 13:35:08 +00:00
wErr = reqCodec.WriteError(soc, 500, err)
2017-11-29 09:55:24 +00:00
} else {
2018-03-22 13:35:08 +00:00
wErr = reqCodec.WriteResponse(soc, result)
2017-11-29 09:55:24 +00:00
}
2018-03-22 13:35:08 +00:00
return wErr
2017-11-29 09:55:24 +00:00
}
2018-03-20 06:31:54 +00:00
func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, params []interface{}) error {
2018-03-22 13:35:08 +00:00
var (
wErr error
)
2017-11-29 09:55:24 +00:00
soc := conn.(server.Socket)
2018-03-22 13:35:08 +00:00
wErr = codec.WriteNotification(soc, method, params)
2017-11-29 09:55:24 +00:00
2018-03-22 13:35:08 +00:00
return wErr
2017-11-29 09:55:24 +00:00
}
2017-11-30 04:59:46 +00:00
func (srwch *ServletReadWriteCloseHandlers) Validate() {
srwch.ServletReadWriteCloseHandlers.Validate()
}