Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ New files that you contribute should use the standard copyright header:
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ go-codec 代码仓库中的文件不列出作者姓名,以避免混乱并避
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
Copyright (C) 2023 Tencent. All rights reserved.

trpc-codec is licensed under the Apache License Version 2.0 except for the third-party components listed below.

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ This repository provides implementations and examples of other protocols, curren
* grpc: Supports grpc protocol
* rawbinary: Supports the protocol where both request and response are `[]byte` under the udp transport layer protocol
* rawstring: Supports the protocol where both request and response are string types under the tcp transport layer protocol, with strings separated by `"\n"`

## Copyright

The copyright notice pertaining to the Tencent code in this repo was previously in the name of “THL A29 Limited.” That entity has now been de-registered. You should treat all previously distributed copies of the code as if the copyright notice was in the name of “Tencent.”
2 changes: 1 addition & 1 deletion grpc/client_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
2 changes: 1 addition & 1 deletion grpc/client_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
2 changes: 1 addition & 1 deletion grpc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
2 changes: 1 addition & 1 deletion grpc/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand Down
94 changes: 47 additions & 47 deletions grpc/examples/clients/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
Expand All @@ -15,59 +15,59 @@
package main

import (
"context"
"fmt"
"log"
"context"
"fmt"
"log"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"trpc.group/trpc-go/trpc-codec/grpc/testdata/protocols/common"
pb "trpc.group/trpc-go/trpc-codec/grpc/testdata/protocols/grpc"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"trpc.group/trpc-go/trpc-codec/grpc/testdata/protocols/common"
pb "trpc.group/trpc-go/trpc-codec/grpc/testdata/protocols/grpc"
)

func main() {
// create a client connection
conn, err := grpc.Dial("127.0.0.1:5051", grpc.WithInsecure())
if err != nil {
panic(err)
}
defer conn.Close()
// create a client connection
conn, err := grpc.Dial("127.0.0.1:5051", grpc.WithInsecure())
if err != nil {
panic(err)
}
defer conn.Close()

// creates an Exporter
exporter, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
// generate TracerProvider
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(exporter),
)
// register TracerProvider
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
tracer := otel.GetTracerProvider().Tracer("grpc-client")
ctx, span := tracer.Start(context.Background(), "hello")
defer span.End()
// creates an Exporter
exporter, err := stdout.New(stdout.WithPrettyPrint())
if err != nil {
log.Fatal(err)
}
// generate TracerProvider
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(exporter),
)
// register TracerProvider
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
tracer := otel.GetTracerProvider().Tracer("grpc-client")
ctx, span := tracer.Start(context.Background(), "hello")
defer span.End()

// injects correlation context and span context into the gRPC
md := metadata.MD{}
otelgrpc.Inject(ctx, &md)
// injects correlation context and span context into the gRPC
md := metadata.MD{}
otelgrpc.Inject(ctx, &md)

// creates a new context with outgoing md attached
ctx = metadata.NewOutgoingContext(ctx, md)
// creates a new context with outgoing md attached
ctx = metadata.NewOutgoingContext(ctx, md)

c := pb.NewGreeterClient(conn)
// send rpc request
if rsp, err := c.Hello(ctx, &common.HelloReq{Msg: "abc"}); err != nil {
panic(err)
} else {
fmt.Print(rsp)
}
c := pb.NewGreeterClient(conn)
// send rpc request
if rsp, err := c.Hello(ctx, &common.HelloReq{Msg: "abc"}); err != nil {
panic(err)
} else {
fmt.Print(rsp)
}

}
Loading
Loading