This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
forked from signalfx/golib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
value.go
72 lines (56 loc) · 1.49 KB
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package datapoint
import (
"fmt"
"strconv"
)
// A Value is the value being sent between servers. It is usually a floating point
// but different systems support different types of values. All values must be printable in some
// human readable interface
type Value interface {
fmt.Stringer
}
type floatWire float64
// FloatValue are values that represent an exact floating point value.
type FloatValue interface {
Value
Float() float64
}
func (wireVal floatWire) Float() float64 {
return float64(wireVal)
}
func (wireVal floatWire) String() string {
return strconv.FormatFloat(float64(wireVal), 'f', -1, 64)
}
// NewFloatValue creates new datapoint value is a float
func NewFloatValue(val float64) FloatValue {
return floatWire(val)
}
type intWire int64
// IntValue are values that represent an exact integer point value.
type IntValue interface {
Value
Int() int64
}
func (wireVal intWire) Int() int64 {
return int64(wireVal)
}
func (wireVal intWire) String() string {
return strconv.FormatInt(int64(wireVal), 10)
}
// NewIntValue creates new datapoint value is an integer
func NewIntValue(val int64) IntValue {
return intWire(val)
}
type strWire string
// StringValue are values that represent an exact string value and don't have a numeric
// representation.
type StringValue interface {
Value
}
func (wireVal strWire) String() string {
return string(wireVal)
}
// NewStringValue creates new datapoint value is a string
func NewStringValue(val string) StringValue {
return strWire(val)
}