From 270bb3982a86dba94348bfafa769ba36f851bfd4 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Thu, 29 Aug 2019 09:30:59 -0700 Subject: [PATCH] Small cleanup of the return values (#180) --- metrics_proto.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/metrics_proto.go b/metrics_proto.go index d7ab229..dd93da2 100644 --- a/metrics_proto.go +++ b/metrics_proto.go @@ -31,7 +31,7 @@ import ( "go.opencensus.io/stats" "go.opencensus.io/trace" - "cloud.google.com/go/monitoring/apiv3" + monitoring "cloud.google.com/go/monitoring/apiv3" distributionpb "google.golang.org/genproto/googleapis/api/distribution" labelpb "google.golang.org/genproto/googleapis/api/label" googlemetricpb "google.golang.org/genproto/googleapis/api/metric" @@ -665,14 +665,13 @@ func fromProtoPoint(startTime *timestamp.Timestamp, pt *metricspb.Point) (*monit return nil, err } - mpt := &monitoringpb.Point{ + return &monitoringpb.Point{ Value: mptv, Interval: &monitoringpb.TimeInterval{ StartTime: startTime, EndTime: pt.Timestamp, }, - } - return mpt, nil + }, nil } func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) { @@ -680,8 +679,6 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) { return nil, nil } - var err error - var tval *monitoringpb.TypedValue switch v := value.(type) { default: // All the other types are not yet handled. @@ -697,21 +694,21 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) { // TODO: Add conversion from SummaryValue when // https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/issues/66 // has been figured out. - err = fmt.Errorf("protoToMetricPoint: unknown Data type: %T", value) + return nil, fmt.Errorf("protoToMetricPoint: unknown Data type: %T", value) case *metricspb.Point_Int64Value: - tval = &monitoringpb.TypedValue{ + return &monitoringpb.TypedValue{ Value: &monitoringpb.TypedValue_Int64Value{ Int64Value: v.Int64Value, }, - } + }, nil case *metricspb.Point_DoubleValue: - tval = &monitoringpb.TypedValue{ + return &monitoringpb.TypedValue{ Value: &monitoringpb.TypedValue_DoubleValue{ DoubleValue: v.DoubleValue, }, - } + }, nil case *metricspb.Point_DistributionValue: dv := v.DistributionValue @@ -749,10 +746,8 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) { mv.DistributionValue.BucketCounts = addZeroBucketCountOnCondition(insertZeroBound, bucketCounts(dv.Buckets)...) } - tval = &monitoringpb.TypedValue{Value: mv} + return &monitoringpb.TypedValue{Value: mv}, nil } - - return tval, err } func bucketCounts(buckets []*metricspb.DistributionValue_Bucket) []int64 {