2017-11-08 06:35:27 +00:00
|
|
|
package gateway
|
|
|
|
|
|
|
|
import (
|
2017-11-09 08:46:44 +00:00
|
|
|
"context"
|
2017-11-08 06:35:27 +00:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"git.loafle.net/commons_go/rpc"
|
|
|
|
"git.loafle.net/commons_go/rpc/protocol"
|
|
|
|
)
|
|
|
|
|
2017-11-09 08:46:44 +00:00
|
|
|
func Handle(ctx context.Context, sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error {
|
2017-11-08 06:35:27 +00:00
|
|
|
return rpc.Handle(sh, codec, r, w, func(codecReq protocol.ServerCodecRequest) (result interface{}, err error) {
|
2017-11-09 08:38:02 +00:00
|
|
|
var params []string
|
2017-11-08 06:35:27 +00:00
|
|
|
if params, err = codecReq.Params(); nil != err {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-09 08:46:44 +00:00
|
|
|
return sh.Invoke(ctx, codecReq.Method(), params)
|
2017-11-08 06:35:27 +00:00
|
|
|
})
|
|
|
|
}
|