30 lines
535 B
Go
30 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
|
||
|
}
|