summaryrefslogtreecommitdiff
path: root/common/common.go
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2023-11-19 13:31:03 +0000
committerhhvn <dev@hhvn.uk>2023-11-19 13:31:28 +0000
commita7e98ba0835c8c7278f298f34fecf6749432fc25 (patch)
treeb5c6f1e4ea2cfeee0da46c0b24cf24918652e81b /common/common.go
parent3ad7ace9c1cc88b4ec4eed8c4eee801e1f659110 (diff)
Status error handling
Diffstat (limited to 'common/common.go')
-rw-r--r--common/common.go14
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
+}