mv file reading operations to data.go

This commit is contained in:
leo 2023-02-25 14:13:56 +01:00
parent b81c38dae4
commit 5694011822
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 17 additions and 9 deletions

@ -63,3 +63,19 @@ func parseRecords(r [][]string) ([][]float64, error) {
return data, nil return data, nil
} }
func readFile(s *string) ([][]float64, error) {
f, err := os.Open(*s)
if err != nil {
return [][]float64{}, err
}
defer f.Close()
data, err := readData(f)
if err != nil {
return [][]float64{}, err
}
return data, nil
}

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"log" "log"
"os"
"git.dotya.ml/wanderer/ak9im/p2/stats" "git.dotya.ml/wanderer/ak9im/p2/stats"
) )
@ -14,14 +13,7 @@ func run() error {
flag.Parse() flag.Parse()
if *datafile != "" { if *datafile != "" {
f, err := os.Open(*datafile) data, err := readFile(datafile)
if err != nil {
return err
}
defer f.Close()
data, err := readData(f)
if err != nil { if err != nil {
return err return err
} }