From a7e98ba0835c8c7278f298f34fecf6749432fc25 Mon Sep 17 00:00:00 2001 From: hhvn Date: Sun, 19 Nov 2023 13:31:03 +0000 Subject: Status error handling --- common/common.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'common') 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 +} -- cgit v1.2.3