package stat import ( "bufio" "io" "strings" ) type DiskFreeStat struct { Filesystem, Size, Used, Available, UsePerc, MountedOn string } func (diskFree DiskFreeStat) Command() string { return "df -k" } func (diskio DiskFreeStat) Parse(r io.Reader) (*[]DiskFreeStat, error) { var scanner = bufio.NewScanner(r) var stats = []DiskFreeStat{} scanner.Scan() for scanner.Scan() { parts := strings.Fields(scanner.Text()) stats = append(stats, DiskFreeStat{ Filesystem: parts[0], Size: parts[1], Used: parts[2], Available: parts[3], UsePerc: removePercUnit(parts[4]), MountedOn: parts[5], }) } return &stats, scanner.Err() } func removePercUnit(str string) string { if !strings.HasSuffix(str, "%") { return str } str = str[:len(str)-1] return str }