Skip to content

Commit

Permalink
fix: refactor direct access references to proto fields
Browse files Browse the repository at this point in the history
Signed-off-by: mikeee <[email protected]>
  • Loading branch information
mikeee committed Dec 7, 2023
1 parent b1a8c13 commit 2ab581f
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 175 deletions.
4 changes: 2 additions & 2 deletions client/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *GRPCClient) InvokeActor(ctx context.Context, in *InvokeActorRequest) (o
out = &InvokeActorResponse{}

if resp != nil {
out.Data = resp.Data
out.Data = resp.GetData()
}

return out, nil
Expand Down Expand Up @@ -421,7 +421,7 @@ func (c *GRPCClient) GetActorState(ctx context.Context, in *GetActorStateRequest
if err != nil {
return nil, fmt.Errorf("error invoking actor get state %s/%s: %w", in.ActorType, in.ActorID, err)
}
return &GetActorStateResponse{Data: rsp.Data}, nil
return &GetActorStateResponse{Data: rsp.GetData()}, nil
}

type ActorStateOperation struct {
Expand Down
4 changes: 2 additions & 2 deletions client/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (c *GRPCClient) InvokeBinding(ctx context.Context, in *InvokeBindingRequest

if resp != nil {
return &BindingEvent{
Data: resp.Data,
Metadata: resp.Metadata,
Data: resp.GetData(),
Metadata: resp.GetMetadata(),
}, nil
}

Expand Down
44 changes: 22 additions & 22 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *testDaprServer) UnlockAlpha1(ctx context.Context, req *pb.UnlockRequest
}

func (s *testDaprServer) InvokeService(ctx context.Context, req *pb.InvokeServiceRequest) (*commonv1pb.InvokeResponse, error) {
if req.Message == nil {
if req.GetMessage() == nil {
return &commonv1pb.InvokeResponse{
ContentType: "text/plain",
Data: &anypb.Any{
Expand All @@ -260,14 +260,14 @@ func (s *testDaprServer) InvokeService(ctx context.Context, req *pb.InvokeServic
}, nil
}
return &commonv1pb.InvokeResponse{
ContentType: req.Message.ContentType,
Data: req.Message.Data,
ContentType: req.GetMessage().GetContentType(),
Data: req.GetMessage().GetData(),
}, nil
}

func (s *testDaprServer) GetState(ctx context.Context, req *pb.GetStateRequest) (*pb.GetStateResponse, error) {
return &pb.GetStateResponse{
Data: s.state[req.Key],
Data: s.state[req.GetKey()],
Etag: "1",
}, nil
}
Expand All @@ -290,35 +290,35 @@ func (s *testDaprServer) GetBulkState(ctx context.Context, in *pb.GetBulkStateRe
}

func (s *testDaprServer) SaveState(ctx context.Context, req *pb.SaveStateRequest) (*empty.Empty, error) {
for _, item := range req.States {
s.state[item.Key] = item.Value
for _, item := range req.GetStates() {
s.state[item.GetKey()] = item.GetValue()
}
return &empty.Empty{}, nil
}

func (s *testDaprServer) QueryStateAlpha1(ctx context.Context, req *pb.QueryStateRequest) (*pb.QueryStateResponse, error) {
var v map[string]interface{}
if err := json.Unmarshal([]byte(req.Query), &v); err != nil {
if err := json.Unmarshal([]byte(req.GetQuery()), &v); err != nil {
return nil, err
}

ret := &pb.QueryStateResponse{
Results: make([]*pb.QueryStateItem, 0, len(s.state)),
}
for key, value := range s.state {
ret.Results = append(ret.Results, &pb.QueryStateItem{Key: key, Data: value})
ret.Results = append(ret.GetResults(), &pb.QueryStateItem{Key: key, Data: value})
}
return ret, nil
}

func (s *testDaprServer) DeleteState(ctx context.Context, req *pb.DeleteStateRequest) (*empty.Empty, error) {
delete(s.state, req.Key)
delete(s.state, req.GetKey())
return &empty.Empty{}, nil
}

func (s *testDaprServer) DeleteBulkState(ctx context.Context, req *pb.DeleteBulkStateRequest) (*empty.Empty, error) {
for _, item := range req.States {
delete(s.state, item.Key)
for _, item := range req.GetStates() {
delete(s.state, item.GetKey())
}
return &empty.Empty{}, nil
}
Expand All @@ -328,9 +328,9 @@ func (s *testDaprServer) ExecuteStateTransaction(ctx context.Context, in *pb.Exe
item := op.GetRequest()
switch opType := op.GetOperationType(); opType {
case "upsert":
s.state[item.Key] = item.Value
s.state[item.GetKey()] = item.GetValue()
case "delete":
delete(s.state, item.Key)
delete(s.state, item.GetKey())
default:
return &empty.Empty{}, fmt.Errorf("invalid operation type: %s", opType)
}
Expand Down Expand Up @@ -362,14 +362,14 @@ func (s *testDaprServer) PublishEvent(ctx context.Context, req *pb.PublishEventR
// It will fail the entire request if an event starts with "failall".
func (s *testDaprServer) BulkPublishEventAlpha1(ctx context.Context, req *pb.BulkPublishRequest) (*pb.BulkPublishResponse, error) {
failedEntries := make([]*pb.BulkPublishResponseFailedEntry, 0)
for _, entry := range req.Entries {
if bytes.HasPrefix(entry.Event, []byte("failall")) {
for _, entry := range req.GetEntries() {
if bytes.HasPrefix(entry.GetEvent(), []byte("failall")) {
// fail the entire request
return nil, errors.New("failed to publish events")
} else if bytes.HasPrefix(entry.Event, []byte("fail")) {
} else if bytes.HasPrefix(entry.GetEvent(), []byte("fail")) {
// fail this entry
failedEntries = append(failedEntries, &pb.BulkPublishResponseFailedEntry{
EntryId: entry.EntryId,
EntryId: entry.GetEntryId(),
Error: "failed to publish events",
})
}
Expand All @@ -378,15 +378,15 @@ func (s *testDaprServer) BulkPublishEventAlpha1(ctx context.Context, req *pb.Bul
}

func (s *testDaprServer) InvokeBinding(ctx context.Context, req *pb.InvokeBindingRequest) (*pb.InvokeBindingResponse, error) {
if req.Data == nil {
if req.GetData() == nil {
return &pb.InvokeBindingResponse{
Data: []byte("test"),
Metadata: map[string]string{"k1": "v1", "k2": "v2"},
}, nil
}
return &pb.InvokeBindingResponse{
Data: req.Data,
Metadata: req.Metadata,
Data: req.GetData(),
Metadata: req.GetMetadata(),
}, nil
}

Expand Down Expand Up @@ -491,12 +491,12 @@ func (s *testDaprServer) SubscribeConfiguration(in *pb.SubscribeConfigurationReq
func (s *testDaprServer) UnsubscribeConfiguration(ctx context.Context, in *pb.UnsubscribeConfigurationRequest) (*pb.UnsubscribeConfigurationResponse, error) {
s.configurationSubscriptionIDMapLoc.Lock()
defer s.configurationSubscriptionIDMapLoc.Unlock()
ch, ok := s.configurationSubscriptionID[in.Id]
ch, ok := s.configurationSubscriptionID[in.GetId()]
if !ok {
return &pb.UnsubscribeConfigurationResponse{Ok: true}, nil
}
close(ch)
delete(s.configurationSubscriptionID, in.Id)
delete(s.configurationSubscriptionID, in.GetId())
return &pb.UnsubscribeConfigurationResponse{Ok: true}, nil
}

Expand Down
22 changes: 11 additions & 11 deletions client/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func (c *GRPCClient) GetConfigurationItems(ctx context.Context, storeName string
}

configItems := make(map[string]*ConfigurationItem)
for k, v := range rsp.Items {
for k, v := range rsp.GetItems() {
configItems[k] = &ConfigurationItem{
Value: v.Value,
Version: v.Version,
Metadata: v.Metadata,
Value: v.GetValue(),
Version: v.GetVersion(),
Metadata: v.GetMetadata(),
}
}
return configItems, nil
Expand Down Expand Up @@ -88,21 +88,21 @@ func (c *GRPCClient) SubscribeConfigurationItems(ctx context.Context, storeName
}
configurationItems := make(map[string]*ConfigurationItem)

for k, v := range rsp.Items {
for k, v := range rsp.GetItems() {
configurationItems[k] = &ConfigurationItem{
Value: v.Value,
Version: v.Version,
Metadata: v.Metadata,
Value: v.GetValue(),
Version: v.GetVersion(),
Metadata: v.GetMetadata(),
}
}
// Get the subscription ID from the first response.
if isFirst {
subscribeIDChan <- rsp.Id
subscribeIDChan <- rsp.GetId()
isFirst = false
}
// Do not invoke handler in case there are no items.
if len(configurationItems) > 0 {
handler(rsp.Id, configurationItems)
handler(rsp.GetId(), configurationItems)
}
}
}()
Expand All @@ -119,7 +119,7 @@ func (c *GRPCClient) UnsubscribeConfigurationItems(ctx context.Context, storeNam
if err != nil {
return fmt.Errorf("unsubscribe failed with error = %w", err)
}
if !resp.Ok {
if !resp.GetOk() {
return fmt.Errorf("unsubscribe error message = %s", resp.GetMessage())
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions client/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func (c *GRPCClient) performCryptoOperation(ctx context.Context, stream grpc.Cli
// Write the data, if any, into the pipe
payload = resProto.GetPayload()
if payload != nil {
if payload.Seq != expectSeq {
pw.CloseWithError(fmt.Errorf("invalid sequence number in chunk: %d (expected: %d)", payload.Seq, expectSeq))
if payload.GetSeq() != expectSeq {
pw.CloseWithError(fmt.Errorf("invalid sequence number in chunk: %d (expected: %d)", payload.GetSeq(), expectSeq))
return
}
expectSeq++

_, readErr = pw.Write(payload.Data)
_, readErr = pw.Write(payload.GetData())
if readErr != nil {
pw.CloseWithError(fmt.Errorf("error writing data: %w", readErr))
return
Expand Down
6 changes: 3 additions & 3 deletions client/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ func (s *testDaprServer) performCryptoOperation(stream grpc.ServerStream, reqPro

payload := reqProto.GetPayload()
if payload != nil {
if payload.Seq != expectSeq {
pw.CloseWithError(fmt.Errorf("invalid sequence number: %d (expected: %d)", payload.Seq, expectSeq))
if payload.GetSeq() != expectSeq {
pw.CloseWithError(fmt.Errorf("invalid sequence number: %d (expected: %d)", payload.GetSeq(), expectSeq))
return
}
expectSeq++

_, err = pw.Write(payload.Data)
_, err = pw.Write(payload.GetData())
if err != nil {
pw.CloseWithError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion client/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *GRPCClient) invokeServiceWithRequest(ctx context.Context, req *pb.Invok

// allow for service to not return any value
if resp != nil && resp.GetData() != nil {
out = resp.GetData().Value
out = resp.GetData().GetValue()
return
}

Expand Down
12 changes: 6 additions & 6 deletions client/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@ func TestVerbParsing(t *testing.T) {
t.Run("valid lower case", func(t *testing.T) {
v := queryAndVerbToHTTPExtension("", "post")
assert.NotNil(t, v)
assert.Equal(t, v1.HTTPExtension_POST, v.Verb)
assert.Len(t, v.Querystring, 0)
assert.Equal(t, v1.HTTPExtension_POST, v.GetVerb())
assert.Empty(t, v.GetQuerystring())
})

t.Run("valid upper case", func(t *testing.T) {
v := queryAndVerbToHTTPExtension("", "GET")
assert.NotNil(t, v)
assert.Equal(t, v1.HTTPExtension_GET, v.Verb)
assert.Equal(t, v1.HTTPExtension_GET, v.GetVerb())
})

t.Run("invalid verb", func(t *testing.T) {
v := queryAndVerbToHTTPExtension("", "BAD")
assert.NotNil(t, v)
assert.Equal(t, v1.HTTPExtension_NONE, v.Verb)
assert.Equal(t, v1.HTTPExtension_NONE, v.GetVerb())
})

t.Run("valid query", func(t *testing.T) {
v := queryAndVerbToHTTPExtension("foo=bar&url=http://dapr.io", "post")
assert.NotNil(t, v)
assert.Equal(t, v1.HTTPExtension_POST, v.Verb)
assert.Equal(t, "foo=bar&url=http://dapr.io", v.Querystring)
assert.Equal(t, v1.HTTPExtension_POST, v.GetVerb())
assert.Equal(t, "foo=bar&url=http://dapr.io", v.GetQuerystring())
})
}

Expand Down
6 changes: 3 additions & 3 deletions client/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *GRPCClient) TryLockAlpha1(ctx context.Context, storeName string, reques
}

return &LockResponse{
Success: resp.Success,
Success: resp.GetSuccess(),
}, nil
}

Expand All @@ -94,7 +94,7 @@ func (c *GRPCClient) UnlockAlpha1(ctx context.Context, storeName string, request
}

return &UnlockResponse{
StatusCode: int32(resp.Status),
Status: pb.UnlockResponse_Status_name[int32(resp.Status)],
StatusCode: int32(resp.GetStatus()),
Status: pb.UnlockResponse_Status_name[int32(resp.GetStatus())],
}, nil
}
54 changes: 27 additions & 27 deletions client/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,48 @@ func (c *GRPCClient) GetMetadata(ctx context.Context) (metadata *GetMetadataResp
return nil, fmt.Errorf("error invoking service: %w", err)
}
if resp != nil {
activeActorsCount := make([]*MetadataActiveActorsCount, len(resp.ActiveActorsCount))
for a := range resp.ActiveActorsCount {
activeActorsCount[a] = &MetadataActiveActorsCount{
Type: resp.ActiveActorsCount[a].Type,
Count: resp.ActiveActorsCount[a].Count,
activeActorsCount := make([]*MetadataActiveActorsCount, len(resp.GetActiveActorsCount()))
for i, a := range resp.GetActiveActorsCount() {
activeActorsCount[i] = &MetadataActiveActorsCount{
Type: a.GetType(),
Count: a.GetCount(),
}
}
registeredComponents := make([]*MetadataRegisteredComponents, len(resp.RegisteredComponents))
for r := range resp.RegisteredComponents {
registeredComponents[r] = &MetadataRegisteredComponents{
Name: resp.RegisteredComponents[r].Name,
Type: resp.RegisteredComponents[r].Type,
Version: resp.RegisteredComponents[r].Version,
Capabilities: resp.RegisteredComponents[r].Capabilities,
registeredComponents := make([]*MetadataRegisteredComponents, len(resp.GetRegisteredComponents()))
for i, r := range resp.GetRegisteredComponents() {
registeredComponents[i] = &MetadataRegisteredComponents{
Name: r.GetName(),
Type: r.GetType(),
Version: r.GetVersion(),
Capabilities: r.GetCapabilities(),
}
}
subscriptions := make([]*MetadataSubscription, len(resp.Subscriptions))
for s := range resp.Subscriptions {
subscriptions := make([]*MetadataSubscription, len(resp.GetSubscriptions()))
for i, s := range resp.GetSubscriptions() {
rules := &PubsubSubscriptionRules{}
for r := range resp.Subscriptions[s].Rules.Rules {
for _, r := range s.GetRules().GetRules() {
rules.Rules = append(rules.Rules, &PubsubSubscriptionRule{
Match: resp.Subscriptions[s].Rules.Rules[r].Match,
Path: resp.Subscriptions[s].Rules.Rules[r].Path,
Match: r.GetMatch(),
Path: r.GetPath(),
})
}

subscriptions[s] = &MetadataSubscription{
PubsubName: resp.Subscriptions[s].PubsubName,
Topic: resp.Subscriptions[s].Topic,
Metadata: resp.Subscriptions[s].Metadata,
subscriptions[i] = &MetadataSubscription{
PubsubName: s.GetPubsubName(),
Topic: s.GetTopic(),
Metadata: s.GetMetadata(),
Rules: rules,
DeadLetterTopic: resp.Subscriptions[s].DeadLetterTopic,
DeadLetterTopic: s.GetDeadLetterTopic(),
}
}
httpEndpoints := make([]*MetadataHTTPEndpoint, len(resp.HttpEndpoints))
for e := range resp.HttpEndpoints {
httpEndpoints[e] = &MetadataHTTPEndpoint{
Name: resp.HttpEndpoints[e].Name,
httpEndpoints := make([]*MetadataHTTPEndpoint, len(resp.GetHttpEndpoints()))
for i, e := range resp.GetHttpEndpoints() {
httpEndpoints[i] = &MetadataHTTPEndpoint{
Name: e.GetName(),
}
}
metadata = &GetMetadataResponse{
ID: resp.Id,
ID: resp.GetId(),
ActiveActorsCount: activeActorsCount,
RegisteredComponents: registeredComponents,
ExtendedMetadata: resp.GetExtendedMetadata(),
Expand Down
Loading

0 comments on commit 2ab581f

Please sign in to comment.