mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-01 13:48:52 +08:00
34 lines
601 B
Go
34 lines
601 B
Go
//
|
|
// gopsutil is a port of psutil(http://pythonhosted.org/psutil/).
|
|
// This covers these architectures.
|
|
// - linux
|
|
// - freebsd
|
|
// - window
|
|
package gopsutil
|
|
|
|
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
|
|
}
|