diff options
Diffstat (limited to 'common/common.go')
| -rw-r--r-- | common/common.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/common/common.go b/common/common.go index c6070f0..1156ee8 100644 --- a/common/common.go +++ b/common/common.go @@ -2,8 +2,10 @@ package common // import "hhvn.uk/hbspbar/common" import ( "os" + "io" "fmt" "strconv" + "strings" ) func Perror(function string, err error) error { @@ -19,3 +21,15 @@ func Intify(s string) (int, error) { i, err := strconv.ParseInt(s, 0, 0) return int(i), err } + +func FileAsLines(file string) ([]string, error) { + f, err := os.Open(file) + if err != nil { return nil, err } + + content, err := io.ReadAll(f) + if err != nil { return nil, err } + + lines := strings.Split(string(content), "\n") + + return lines, nil +} |