sys-exporter/collector/sysinfo/utils.go
Melora Hugues 5df32a9b98
All checks were successful
/ go-test (push) Successful in 9m48s
Add sysinfo collector
2024-12-07 17:19:05 +01:00

29 lines
535 B
Go

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
}