Skip to content

Commit 7f59f2a

Browse files
fix: add multi params support (#7)
* fix: add multi params support * fix : remove ci auto build * fix: rm ql
1 parent 11b9e6e commit 7f59f2a

7 files changed

Lines changed: 37 additions & 75 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

internal/codec/twoway_codec_impl/twoway_codec_impl.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
package twoway_codec_impl
1919

20-
import (
21-
perrors "github.com/pkg/errors"
22-
)
23-
2420
import (
2521
"github.com/dubbogo/triple/internal/codec"
2622
"github.com/dubbogo/triple/internal/codec/codec_impl"
2723
proto2 "github.com/dubbogo/triple/internal/codec/proto"
24+
"github.com/dubbogo/triple/internal/codes"
25+
"github.com/dubbogo/triple/internal/status"
2826
"github.com/dubbogo/triple/pkg/common"
2927
"github.com/dubbogo/triple/pkg/common/constant"
3028
)
@@ -65,12 +63,15 @@ func NewPBWrapperTwoWayCodec(codecName constant.CodecType) (common.TwoWayCodec,
6563
func (h *PBWrapperTwoWayCodec) MarshalRequest(v interface{}) ([]byte, error) {
6664
argsBytes := make([][]byte, 0)
6765
argsTypes := make([]string, 0)
68-
data, err := h.codec.Marshal(v)
69-
if err != nil {
70-
return nil, err
66+
reqList := v.([]interface{})
67+
for _, value := range reqList {
68+
data, err := h.codec.Marshal(value)
69+
if err != nil {
70+
return nil, err
71+
}
72+
argsBytes = append(argsBytes, data)
73+
argsTypes = append(argsTypes, codec.GetArgType(value))
7174
}
72-
argsBytes = append(argsBytes, data)
73-
argsTypes = append(argsTypes, codec.GetArgType(v))
7475

7576
wrapperRequest := &proto2.TripleRequestWrapper{
7677
SerializeType: common.GetCodecInWrapperName(h.codecName),
@@ -87,12 +88,18 @@ func (h *PBWrapperTwoWayCodec) UnmarshalRequest(data []byte, v interface{}) erro
8788
if err != nil {
8889
return err
8990
}
90-
if len(wrapperRequest.Args) != 1 {
91-
return perrors.New("wrapper request args len is not 1")
91+
92+
paramsInterfaces := v.([]interface{})
93+
if len(paramsInterfaces) != len(wrapperRequest.Args) {
94+
return status.Errorf(codes.Internal, "error ,request params len is %d, but exported method has %d", len(wrapperRequest.Args), len(paramsInterfaces))
9295
}
93-
if err := h.codec.Unmarshal(wrapperRequest.Args[0], v); err != nil {
94-
return err
96+
97+
for idx, value := range wrapperRequest.Args {
98+
if err := h.codec.Unmarshal(value, paramsInterfaces[idx]); err != nil {
99+
return err
100+
}
95101
}
102+
96103
return nil
97104
}
98105

internal/http2_handler/tri_http2_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (hc *H2Controller) UnaryInvoke(ctx context.Context, path string, arg, reply
343343
HeaderField: newHeader,
344344
})
345345
if err != nil {
346-
hc.option.Logger.Errorf("triple unary invoke path %s with addr = %s error = %v", path, hc.address, err)
346+
hc.option.Logger.Error("triple unary invoke path" + path + " with addr = " + hc.address + " error = " + err.Error())
347347
return err
348348
}
349349

internal/stream/processor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (p *unaryProcessor) processUnaryRPC(buf bytes.Buffer, service interface{},
123123
if !ok {
124124
return nil, status.Errorf(codes.Internal, "msgpack provider service doesn't impl TripleUnaryService")
125125
}
126-
reqParam, ok := unaryService.GetReqParamsInteface(methodName)
126+
reqParam, ok := unaryService.GetReqParamsInterfaces(methodName)
127127
if !ok {
128128
return nil, status.Errorf(codes.Internal, "provider unmarshal error: no req param data")
129129
}
@@ -137,9 +137,12 @@ func (p *unaryProcessor) processUnaryRPC(buf bytes.Buffer, service interface{},
137137
if err = p.twoWayCodec.UnmarshalRequest(readBuf, reqParam); err != nil {
138138
return nil, status.Errorf(codes.Internal, "Unary rpc request unmarshal error: %s", err)
139139
}
140-
args := make([]interface{}, 0, 1)
141-
reqParam = reflect.ValueOf(reqParam).Elem().Interface()
142-
args = append(args, reqParam)
140+
args := make([]interface{}, 0, len(reqParam))
141+
for _, v := range reqParam {
142+
tempParamObj := reflect.ValueOf(v).Elem().Interface()
143+
args = append(args, tempParamObj)
144+
}
145+
143146
reply, err = unaryService.InvokeWithArgs(header.FieldToCtx(), methodName, args)
144147
}
145148

pkg/common/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ type TripleGrpcService interface {
3333
// TripleUnaryService is normal protocol service (except grpc service), should be implemented by users
3434
type TripleUnaryService interface {
3535
InvokeWithArgs(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error)
36-
GetReqParamsInteface(methodName string) (interface{}, bool)
36+
GetReqParamsInterfaces(methodName string) ([]interface{}, bool)
3737
}

pkg/http2/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ LOOP:
216216
}
217217

218218
if timeoutFlag {
219-
h.logger.Errorf("unary call %s with addr = %s timeout", path, addr)
219+
h.logger.Error("unary call" + path + " with addr = " + addr + " timeout")
220220
return nil, nil, perrors.Errorf("unary call %s timeout", path)
221221
}
222222

pkg/triple/dubbo3_client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ func (t *TripleClient) Invoke(methodName string, in []reflect.Value, reply inter
8787
} else {
8888
ctx := in[0].Interface().(context.Context)
8989
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
90-
err := t.Request(ctx, "/"+interfaceKey+"/"+methodName, in[1].Interface(), reply)
90+
reqParams := make([]interface{}, 0, len(in)-1)
91+
for idx, v := range in {
92+
if idx > 0 {
93+
reqParams = append(reqParams, v.Interface())
94+
}
95+
}
96+
err := t.Request(ctx, "/"+interfaceKey+"/"+methodName, reqParams, reply)
9197
if err != nil {
9298
return err
9399
}

0 commit comments

Comments
 (0)