This commit is contained in:
crusader 2017-11-09 17:46:44 +09:00
parent eac00359db
commit 8c1c86f021
3 changed files with 8 additions and 4 deletions

View File

@ -1,18 +1,19 @@
package gateway
import (
"context"
"io"
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol"
)
func Handle(sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error {
func Handle(ctx context.Context, sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error {
return rpc.Handle(sh, codec, r, w, func(codecReq protocol.ServerCodecRequest) (result interface{}, err error) {
var params []string
if params, err = codecReq.Params(); nil != err {
return nil, err
}
return sh.Invoke(codecReq.Method(), params)
return sh.Invoke(ctx, codecReq.Method(), params)
})
}

View File

@ -1,11 +1,13 @@
package gateway
import (
"context"
"git.loafle.net/commons_go/rpc"
)
type ServerHandler interface {
rpc.ServerHandler
Invoke(method string, params []string) (result interface{}, err error)
Invoke(ctx context.Context, method string, params []string) (result interface{}, err error)
}

View File

@ -1,6 +1,7 @@
package gateway
import (
"context"
"errors"
"git.loafle.net/commons_go/rpc"
@ -10,7 +11,7 @@ type ServerHandlers struct {
rpc.ServerHandlers
}
func (sh *ServerHandlers) Invoke(method string, params []string) (result interface{}, err error) {
func (sh *ServerHandlers) Invoke(ctx context.Context, method string, params []string) (result interface{}, err error) {
return nil, errors.New("Server: Handler method[Invoke] of Server is not implement")
}