forked from daBONDi/go-rest-wol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
38 lines (30 loc) · 950 Bytes
/
data.go
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
package main
import (
"log"
"os"
"github.com/gocarina/gocsv"
)
// LoadComputerList loads the Computer and return the readed list or an error
func loadComputerList(computerCsvFilePath string) ([]Computer, error) {
var computers []Computer
computerCsvFilePointer, computerCsvFileOpenError := os.Open(computerCsvFilePath)
if computerCsvFileOpenError != nil {
log.Fatalf("Error on Opening the file")
return computers, computerCsvFileOpenError
}
if computerCsvFileParserError := gocsv.UnmarshalFile(computerCsvFilePointer, &computers); computerCsvFileParserError != nil {
computerCsvFilePointer.Close()
return computers, computerCsvFileParserError
}
computerCsvFilePointer.Close()
return computers, nil
}
// Test if Path is a File and it exist
func FileExists(name string) bool {
if fi, err := os.Stat(name); err == nil {
if fi.Mode().IsRegular() {
return true
}
}
return false
}