apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.69k stars 917 forks source link

fix: Server return with Attachment #2648

Closed YarBor closed 5 months ago

YarBor commented 6 months ago

fix: Server return with Attachment (#2641)

in this pr, every call will return all attachment-data , whether built-in data or user-attached data. in triple unray call

but in this issue i have no idea to fix it in an elegant way

I tried adding new fields like (userAttachmentKey or whatever) but it's not very nice to separate the built-in data from the user-attached data. I also thought about modifying the key of user-attached data before transfer and restoring it after transfer, but that doesn't seem feasible in this question (called in curl mode).

there may need some good idea?

but in this issue i have no idea to fix it in an elegant way

I tried adding new fields like (userAttachmentKey or whatever) but it's not very nice to separate the built-in data from the user-attached data. I also thought about modifying the key of user-attached data before transfer and restoring it after transfer, but that doesn't seem feasible in this question (called in curl mode).

there may need some good idea?

add new api

One possible point to discuss is that in the additional data received by both parties, the first letter of the key will be changed to a capital letter.

client-side-call

func rpcCaller(){
        header := http.Header{"testKey1": []string{"testVal1"}, "testKey2": []string{"testVal2"}}
        // to store outgoing data ,and reserve the location for the receive field.
        // header will be copy , and header's key will change to be lowwer. 
    ctx, _ := triple_protocol.NewOutgoingContext(context.Background(), header )

        res, err := cli.Greet(ctx, &greet.GreetRequest{Name: "triple"})
    // stream, err := cli.GreetServerStream(ctx, &greet.GreetServerStreamRequest{Name: "triple"})
        // stream, err := cli.GreetStream(ctx)
        // stream, err := cli.GreetClientStream(ctx)

        /* 
             do something and close connection.
        */ 

        // to get return data , and key is lowwer , like grpc.
        data, err := triple_protocol.FromIncomingContext(ctx)
}

server-side

func (impl *Impl) ****call(ctx context.Context, *** api.Req) (*** , errno){
    data, _ := triple.FromIncomingContext(ctx)

        // do something

        triple.SetOutgoingData(ctx , http.Header{"OutgoingDataKey1" , []string{"OutgoingDataVal1"}})
    /* OR */ 
        triple.AppendToOutgoingContext(ctx, "OutgoingContextKey2", "OutgoingDataVal2")
}

new api applies to all 4 calling methods.

codecov-commenter commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 47.31%. Comparing base (1bd6abc) to head (1bd6abc).

:exclamation: Current head 1bd6abc differs from pull request most recent head 57227f3. Consider uploading reports for the commit 57227f3 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2648 +/- ## ======================================= Coverage 47.31% 47.31% ======================================= Files 341 341 Lines 25165 25165 ======================================= Hits 11908 11908 Misses 12106 12106 Partials 1151 1151 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud