diff --git a/go.mod b/go.mod index 49c29a55007..f558230a77c 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,8 @@ go 1.25.9 // We fork this bc the stock version of this library is over 20mb. replace github.com/hashicorp/go-getter => github.com/viam-labs/go-getter v0.0.0-20251022162721-98d73b852c8a +replace go.viam.com/api => ../api + require ( github.com/AlekSi/gocov-xml v1.0.0 github.com/Masterminds/semver/v3 v3.3.1 diff --git a/go.sum b/go.sum index 4a50ad7f762..eb8669b1c7d 100644 --- a/go.sum +++ b/go.sum @@ -1158,8 +1158,6 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -go.viam.com/api v0.1.555 h1:ncBlAwDpEk658aouQLoeq1RLDqdi3spWVFN0y6nsvXM= -go.viam.com/api v0.1.555/go.mod h1:nVe4WXrtc8aupJ8OWXSYx6KhCiOkr3VCbkwxD4D41xQ= go.viam.com/test v1.2.4 h1:JYgZhsuGAQ8sL9jWkziAXN9VJJiKbjoi9BsO33TW3ug= go.viam.com/test v1.2.4/go.mod h1:zI2xzosHdqXAJ/kFqcN+OIF78kQuTV2nIhGZ8EzvaJI= go.viam.com/utils v0.6.1 h1:xJhq+S2ADMTDj9538blmhI0otZCRAZUonRBkb+zHIHo= diff --git a/resource/response_metadata.go b/resource/response_metadata.go index e7c5fd67b2d..7bb643a0959 100644 --- a/resource/response_metadata.go +++ b/resource/response_metadata.go @@ -4,18 +4,29 @@ import ( "time" commonpb "go.viam.com/api/common/v1" + "google.golang.org/protobuf/types/known/structpb" "google.golang.org/protobuf/types/known/timestamppb" ) // ResponseMetadata contains extra info associated with a Resource's standard response. type ResponseMetadata struct { CapturedAt time.Time + Attributes map[string]interface{} } // AsProto turns the ResponseMetadata struct into a protobuf message. func (rm ResponseMetadata) AsProto() *commonpb.ResponseMetadata { metadata := &commonpb.ResponseMetadata{} metadata.CapturedAt = timestamppb.New(rm.CapturedAt) + attributes := make(map[string]*structpb.Value) + for k, v := range rm.Attributes { + value, err := structpb.NewValue(v) + if err != nil { + continue + } + attributes[k] = value + } + metadata.Attributes = &structpb.Struct{Fields: attributes} return metadata } @@ -23,5 +34,6 @@ func (rm ResponseMetadata) AsProto() *commonpb.ResponseMetadata { func ResponseMetadataFromProto(proto *commonpb.ResponseMetadata) ResponseMetadata { metadata := ResponseMetadata{} metadata.CapturedAt = proto.CapturedAt.AsTime() + metadata.Attributes = proto.Attributes.AsMap() return metadata } diff --git a/resource/response_metadata_test.go b/resource/response_metadata_test.go index 831ffbe8bc5..1ce4b617eed 100644 --- a/resource/response_metadata_test.go +++ b/resource/response_metadata_test.go @@ -6,19 +6,22 @@ import ( commonpb "go.viam.com/api/common/v1" "go.viam.com/test" + "google.golang.org/protobuf/types/known/structpb" "google.golang.org/protobuf/types/known/timestamppb" ) func TestResponseToProto(t *testing.T) { ts := time.UnixMilli(12345) - metadata := ResponseMetadata{CapturedAt: ts} + metadata := ResponseMetadata{CapturedAt: ts, Attributes: map[string]interface{}{"key": "value"}} proto := metadata.AsProto() test.That(t, proto.CapturedAt.AsTime(), test.ShouldEqual, ts) + test.That(t, proto.Attributes.Fields["key"].GetStringValue(), test.ShouldEqual, "value") } func TestResponseFromProto(t *testing.T) { ts := ×tamppb.Timestamp{Seconds: 12, Nanos: 345000000} - proto := &commonpb.ResponseMetadata{CapturedAt: ts} + proto := &commonpb.ResponseMetadata{CapturedAt: ts, Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{"key": {Kind: &structpb.Value_StringValue{StringValue: "value"}}}}} metadata := ResponseMetadataFromProto(proto) test.That(t, metadata.CapturedAt, test.ShouldEqual, time.UnixMilli(12345)) + test.That(t, metadata.Attributes["key"], test.ShouldEqual, "value") }