shirou_gopsutil/common.go

28 lines
453 B
Go
Raw Normal View History

2014-04-18 15:34:47 +08:00
package main
import (
"bufio"
"os"
"strings"
)
// Read contents from file and split by new line.
func ReadLines(filename string) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return []string{""}, err
}
defer f.Close()
ret := make([]string, 0)
r := bufio.NewReader(f)
line, err := r.ReadString('\n')
for err == nil {
ret = append(ret, strings.Trim(line, "\n"))
line, err = r.ReadString('\n')
}
return ret, err
}