-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.go
More file actions
58 lines (51 loc) · 1.06 KB
/
file.go
File metadata and controls
58 lines (51 loc) · 1.06 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// File struct contains
type File struct {
filename string
processed bool
}
// todo find a better way to search through the slice
func isFileProcessed(list *[]File, filename string) bool {
for _, f := range *list {
if f.filename == filename {
return f.processed
}
}
return false
}
func getInputFileFormat(fileName os.FileInfo, formatType string) bool {
if formatType == "" {
return false
}
name := fileName.Name()
fileFormat := strings.Join(strings.Split(name, ".")[1:], ".")
if fileFormat == formatType {
return true
}
return false
}
func saveFile(myFile *bytes.Buffer, path string) error {
if err := ioutil.WriteFile(path, myFile.Bytes(), os.FileMode(0644)); err != nil {
return err
}
return nil
}
func getPath() string {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
logger.Printf("Error: %s", err.Error())
}
return dir
}
func isJSON(str []byte) bool {
var js json.RawMessage
return json.Unmarshal(str, &js) == nil
}