diff options
| author | hhvn <dev@hhvn.uk> | 2023-11-19 13:31:03 +0000 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2023-11-19 13:31:28 +0000 |
| commit | a7e98ba0835c8c7278f298f34fecf6749432fc25 (patch) | |
| tree | b5c6f1e4ea2cfeee0da46c0b24cf24918652e81b /common | |
| parent | 3ad7ace9c1cc88b4ec4eed8c4eee801e1f659110 (diff) | |
Status error handling
Diffstat (limited to 'common')
| -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 +} |