Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
Signed-off-by: YarBor <yarbor.ww@gmail.com>
  • Loading branch information
YarBor committed Apr 21, 2024
1 parent d09d80f commit 44965e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions protocol/triple/triple_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (ti *TripleInvoker) Invoke(ctx context.Context, invocation protocol.Invocat
return &result
}

ctx, err = mergeAttachmentToOutgoing(ctx, invocation.Attachments())
ctx, err = mergeAttachmentToOutgoing(ctx, invocation)
if err != nil {
result.SetError(err)
return &result
Expand Down Expand Up @@ -143,15 +143,15 @@ func (ti *TripleInvoker) Invoke(ctx context.Context, invocation protocol.Invocat
return &result
}

func mergeAttachmentToOutgoing(ctx context.Context, attachments map[string]interface{}) (context.Context, error) {
for key, valRaw := range attachments {
func mergeAttachmentToOutgoing(ctx context.Context, inv protocol.Invocation) (context.Context, error) {
for key, valRaw := range inv.Attachments() {
if str, ok := valRaw.(string); ok {
ctx, _ = tri.AppendToOutgoingContext(ctx, key, str)
ctx = tri.AppendToOutgoingContext(ctx, key, str)
continue
}
if strs, ok := valRaw.([]string); ok {
for _, str := range strs {
ctx, _ = tri.AppendToOutgoingContext(ctx, key, str)
ctx = tri.AppendToOutgoingContext(ctx, key, str)
}
continue
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/triple/triple_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func Test_parseAttachments(t *testing.T) {
ctx := test.ctx()
inv := test.invo()
parseAttachments(ctx, test.url, inv)
ctx, err := mergeAttachmentToOutgoing(ctx, inv.Attachments())
ctx, err := mergeAttachmentToOutgoing(ctx, inv)
test.expect(t, ctx, err)
})
}
Expand Down
8 changes: 4 additions & 4 deletions protocol/triple/triple_protocol/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func newIncomingContext(ctx context.Context, data http.Header) context.Context {
// It is used for passing headers to server-side.
// It is like grpc.NewOutgoingContext.
// Please refer to https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#sending-metadata.
func NewOutgoingContext(ctx context.Context, data http.Header) (context.Context, error) {
func NewOutgoingContext(ctx context.Context, data http.Header) context.Context {
var header = http.Header{}
if data != nil {
for key, vals := range data {
Expand All @@ -127,14 +127,14 @@ func NewOutgoingContext(ctx context.Context, data http.Header) (context.Context,
extraData = map[string]http.Header{}
}
extraData[headerOutgoingKey] = header
return context.WithValue(ctx, extraDataKey{}, extraData), nil
return context.WithValue(ctx, extraDataKey{}, extraData)
}

// AppendToOutgoingContext merges kv pairs from user and existing headers.
// It is used for passing headers to server-side.
// It is like grpc.AppendToOutgoingContext.
// Please refer to https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md#sending-metadata.
func AppendToOutgoingContext(ctx context.Context, kv ...string) (context.Context, error) {
func AppendToOutgoingContext(ctx context.Context, kv ...string) context.Context {
if len(kv)%2 == 1 {
panic(fmt.Sprintf("AppendToOutgoingContext got an odd number of input pairs for header: %d", len(kv)))
}
Expand All @@ -152,7 +152,7 @@ func AppendToOutgoingContext(ctx context.Context, kv ...string) (context.Context
// todo(DMwangnima): think about lowering
header.Add(strings.ToLower(kv[i]), kv[i+1])
}
return ctx, nil
return ctx
}

func ExtractFromOutgoingContext(ctx context.Context) http.Header {
Expand Down

0 comments on commit 44965e4

Please sign in to comment.