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" ),
0 commit comments