-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
42 lines (34 loc) · 870 Bytes
/
utils.go
File metadata and controls
42 lines (34 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package rankreq
import (
"bufio"
"encoding/csv"
"errors"
"os"
"strconv"
"strings"
)
// FileDescribe opens a file and returns a reader
func FileDescribe(path string) (*os.File, *csv.Reader, error) {
tsvFile, err := os.Open(path)
if err != nil {
return nil, nil, errors.New("Open error")
}
return tsvFile, csv.NewReader(bufio.NewReader(tsvFile)), nil
}
// ParseTime returns a slice of time tokens
func ParseTime(time string, r *strings.Replacer, checkLen bool) ([]int64, error) {
result := r.Replace(time)
timeTokens := strings.Split(result, "-")
if checkLen && len(timeTokens) != 6 {
return nil, errors.New("Wrong format")
}
var ret []int64
for _, timeToken := range timeTokens {
time, err := strconv.ParseInt(timeToken, 10, 64)
if err != nil {
return nil, errors.New("Wrong format")
}
ret = append(ret, time)
}
return ret, nil
}