github.com/blend/go-sdk@v1.20220411.3/statsd/metric.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package statsd 9 10 import ( 11 "strconv" 12 "time" 13 ) 14 15 // Metric is a statsd metric. 16 type Metric struct { 17 Name string 18 Type string 19 Value string 20 Tags []string 21 } 22 23 // Float64 returns the value parsed as a float64. 24 func (m Metric) Float64() (float64, error) { 25 return strconv.ParseFloat(m.Value, 64) 26 } 27 28 // Int64 returns the value parsed as an int64. 29 func (m Metric) Int64() (int64, error) { 30 return strconv.ParseInt(m.Value, 10, 64) 31 } 32 33 // Duration is the value parsed as a duration assuming 34 // it was a float64 of milliseconds. 35 func (m Metric) Duration() (time.Duration, error) { 36 f64, err := m.Float64() 37 if err != nil { 38 return 0, err 39 } 40 return time.Duration(f64 * float64(time.Millisecond)), nil 41 }