diff options
Diffstat (limited to 'collector/helper.go')
-rw-r--r-- | collector/helper.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/collector/helper.go b/collector/helper.go index 2bf461e..df5cd26 100644 --- a/collector/helper.go +++ b/collector/helper.go | |||
@@ -14,6 +14,7 @@ | |||
14 | package collector | 14 | package collector |
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "bytes" | ||
17 | "io/ioutil" | 18 | "io/ioutil" |
18 | "strconv" | 19 | "strconv" |
19 | "strings" | 20 | "strings" |
@@ -30,3 +31,16 @@ func readUintFromFile(path string) (uint64, error) { | |||
30 | } | 31 | } |
31 | return value, nil | 32 | return value, nil |
32 | } | 33 | } |
34 | |||
35 | // Take a []byte{} and return a string based on null termination. | ||
36 | // This is useful for situations where the OS has returned a null terminated | ||
37 | // string to use. | ||
38 | // If this function happens to receive a byteArray that contains no nulls, we | ||
39 | // simply convert the array to a string with no bounding. | ||
40 | func bytesToString(byteArray []byte) string { | ||
41 | n := bytes.IndexByte(byteArray, 0) | ||
42 | if n < 0 { | ||
43 | return string(byteArray) | ||
44 | } | ||
45 | return string(byteArray[:n]) | ||
46 | } | ||