sys-exporter/collector/sysinfo/utils.go

30 lines
535 B
Go
Raw Permalink Normal View History

2024-12-07 16:19:05 +00:00
package sysinfo
import (
"fmt"
"strings"
)
func parseOSRelease(content []byte) (map[string]string, error) {
res := make(map[string]string)
for _, line := range strings.Split(string(content), "\n") {
if line == "" {
continue
}
lineVals := strings.SplitN(line, "=", 2)
if len(lineVals) != 2 {
return nil, fmt.Errorf("impossible to split line %q", line)
}
if _, ok := res[lineVals[0]]; ok {
return nil, fmt.Errorf("duplicate key %q", lineVals[0])
}
res[lineVals[0]] = lineVals[1]
}
return res, nil
}