| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package util |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "encoding/csv" |
||
| 5 | "log" |
||
| 6 | "os" |
||
| 7 | "path/filepath" |
||
| 8 | "strings" |
||
| 9 | ) |
||
| 10 | |||
| 11 | func MustOpenReadonlyFile(filename string) *os.File { |
||
|
1 ignored issue
–
show
|
|||
| 12 | file, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm) |
||
| 13 | if err != nil { |
||
| 14 | log.Fatalln(err) |
||
| 15 | } |
||
| 16 | |||
| 17 | return file |
||
| 18 | } |
||
| 19 | |||
| 20 | func GetCSVReader(file *os.File, sep rune) *csv.Reader { |
||
|
1 ignored issue
–
show
|
|||
| 21 | reader := csv.NewReader(file) |
||
| 22 | reader.Comma = sep |
||
| 23 | reader.FieldsPerRecord = -1 |
||
| 24 | |||
| 25 | return reader |
||
| 26 | } |
||
| 27 | |||
| 28 | func FileExists(filename string) bool { |
||
|
1 ignored issue
–
show
|
|||
| 29 | _, err := os.Stat(filename) |
||
| 30 | |||
| 31 | return err == nil |
||
| 32 | } |
||
| 33 | |||
| 34 | func Extension(filename string) string { |
||
|
1 ignored issue
–
show
|
|||
| 35 | return strings.Trim(filepath.Ext(filename), ".") |
||
| 36 | } |
||
| 37 | |||
| 38 | func Abs(path string) string { |
||
|
1 ignored issue
–
show
|
|||
| 39 | abs, err := filepath.Abs(path) |
||
| 40 | if err == nil { |
||
| 41 | return abs |
||
| 42 | } |
||
| 43 | |||
| 44 | return path |
||
| 45 | } |
||
| 46 | |||
| 47 | func PathsEqual(p1, p2 string) bool { |
||
|
1 ignored issue
–
show
|
|||
| 48 | p1 = strings.TrimRight(p1, "/\\") |
||
| 49 | p2 = strings.TrimRight(p2, "/\\") |
||
| 50 | |||
| 51 | if p1 == p2 { |
||
| 52 | return true |
||
| 53 | } |
||
| 54 | |||
| 55 | if filepath.FromSlash(p1) == filepath.FromSlash(p2) { |
||
| 56 | return true |
||
| 57 | } |
||
| 58 | |||
| 59 | if filepath.ToSlash(p1) == filepath.ToSlash(p2) { |
||
| 60 | return true |
||
| 61 | } |
||
| 62 | |||
| 63 | return false |
||
| 64 | } |
||
| 65 |