Skip to content

Commit 14aff55

Browse files
authored
do not use data with content-type (#17)
1 parent 1826fb8 commit 14aff55

File tree

3 files changed

+72
-115
lines changed

3 files changed

+72
-115
lines changed

dapr/proto/common/v1/common.pb.go

Lines changed: 60 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/caller/main.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
commonv1pb "github.com/dapr/go-sdk/dapr/proto/common/v1"
99
pb "github.com/dapr/go-sdk/dapr/proto/dapr/v1"
10-
"github.com/golang/protobuf/ptypes"
1110
"github.com/golang/protobuf/ptypes/any"
1211
"google.golang.org/grpc"
1312
)
@@ -26,32 +25,24 @@ func main() {
2625
// Create the client
2726
client := pb.NewDaprClient(conn)
2827

29-
d, err := ptypes.MarshalAny(&commonv1pb.DataWithContentType{
30-
ContentType: "text/plain; charset=UTF-8",
31-
Body: []byte("Hello"),
32-
})
33-
if err != nil {
34-
panic(err)
35-
}
36-
3728
// Invoke a method called MyMethod on another Dapr enabled service with id client
3829
resp, err := client.InvokeService(context.Background(), &pb.InvokeServiceRequest{
3930
Id: "client",
4031
Message: &commonv1pb.InvokeRequest{
41-
Method: "MyMethod",
42-
Data: d,
32+
Method: "MyMethod",
33+
ContentType: "text/plain; charset=UTF-8",
34+
Data: &any.Any{Value: []byte("Hello")},
4335
},
4436
})
4537
if err != nil {
4638
panic(err)
4739
}
48-
var value = &commonv1pb.DataWithContentType{}
49-
ptypes.UnmarshalAny(resp.Data, value)
50-
if value.GetContentType() != "text/plain; charset=UTF-8" {
51-
fmt.Printf("wrong content type: %s", value.GetContentType())
40+
41+
if resp.GetContentType() != "text/plain; charset=UTF-8" {
42+
fmt.Printf("wrong content type: %s", resp.GetContentType())
5243
}
5344

54-
fmt.Println(string(value.Body))
45+
fmt.Println(string(resp.GetData().GetValue()))
5546

5647
// Publish a message to the topic TopicA
5748
_, err = client.PublishEvent(context.Background(), &pb.PublishEventEnvelope{
@@ -71,7 +62,7 @@ func main() {
7162
// statestore is the name of the default redis state store , set up by Dapr CLI
7263
StoreName: "statestore",
7364
Requests: []*pb.StateRequest{
74-
&pb.StateRequest{
65+
{
7566
Key: "myKey",
7667
Value: &any.Any{
7768
Value: []byte("My State"),

example/client/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"net"
88

9-
"github.com/golang/protobuf/ptypes"
9+
"github.com/golang/protobuf/ptypes/any"
1010
"github.com/golang/protobuf/ptypes/empty"
1111

1212
commonv1pb "github.com/dapr/go-sdk/dapr/proto/common/v1"
@@ -54,12 +54,10 @@ func (s *server) OnInvoke(ctx context.Context, in *commonv1pb.InvokeRequest) (*c
5454
response = s.MyMethod()
5555
}
5656

57-
d := &commonv1pb.DataWithContentType{
57+
return &commonv1pb.InvokeResponse{
5858
ContentType: "text/plain; charset=UTF-8",
59-
Body: []byte(response),
60-
}
61-
resp, err := ptypes.MarshalAny(d)
62-
return &commonv1pb.InvokeResponse{Data: resp}, err
59+
Data: &any.Any{Value: []byte(response)},
60+
}, nil
6361
}
6462

6563
// Dapr will call this method to get the list of topics the app wants to subscribe to. In this example, we are telling Dapr

0 commit comments

Comments
 (0)