Skip to content

Commit 5dd841c

Browse files
authored
Merge pull request #1745 from FelixTing/issue-1744
fix: Replace fmt.Sprintf("%v",v) with cast.ToString(v)
2 parents 324e885 + f66955f commit 5dd841c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/transforms/metrics.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2022 Intel Corporation
3+
// Copyright (c) 2025 IOTech Ltd
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
56
// you may not use this file except in compliance with the License.
@@ -22,6 +23,8 @@ import (
2223
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos"
2324

2425
"github.com/edgexfoundry/app-functions-sdk-go/v4/pkg/interfaces"
26+
27+
"github.com/spf13/cast"
2528
)
2629

2730
// MetricsProcessor contains functions to process the Metric DTO
@@ -38,7 +41,7 @@ func NewMetricsProcessor(additionalTags map[string]interface{}) (*MetricsProcess
3841
return nil, err
3942
}
4043

41-
mp.additionalTags = append(mp.additionalTags, dtos.MetricTag{Name: name, Value: fmt.Sprintf("%v", value)})
44+
mp.additionalTags = append(mp.additionalTags, dtos.MetricTag{Name: name, Value: cast.ToString(value)})
4245
}
4346

4447
return mp, nil

pkg/transforms/metrics_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2022 Intel Corporation
3+
// Copyright (c) 2025 IOTech Ltd
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
56
// you may not use this file except in compliance with the License.
@@ -37,11 +38,13 @@ func TestNewMetricsProcessor(t *testing.T) {
3738
"Tag1": "str1",
3839
"Tag2": 123,
3940
"Tag3": 12.34,
41+
"Tag4": 1234567.1,
4042
}
4143
expectedTags := []dtos.MetricTag{
4244
{Name: "Tag1", Value: "str1"},
4345
{Name: "Tag2", Value: "123"},
4446
{Name: "Tag3", Value: "12.34"},
47+
{Name: "Tag4", Value: "1234567.1"},
4548
}
4649

4750
actual, err = NewMetricsProcessor(inputTags)

0 commit comments

Comments
 (0)