-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_helper.go
52 lines (41 loc) · 934 Bytes
/
io_helper.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"os"
"path/filepath"
"io/ioutil"
)
//Check if file path exists
func Exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil { return true, nil }
if os.IsNotExist(err) { return false, nil }
return true, err
}
//Returns true or false if secrets file exists
func CheckForSecretsFile(env string, mkdir bool) (bool, string) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
panic(err)
}
dir += "/secrets"
if(mkdir) {
os.MkdirAll(dir, os.ModePerm) //Ensure dir exists
}
dir += "/" + env
secretsExist, err := Exists(dir)
return secretsExist, dir
}
//TODO: Filemode
func WriteFile(path string, contents []byte) {
err := ioutil.WriteFile(path, contents, 0644)
if(err != nil) {
panic(err)
}
}
func ReadFile(path string) []byte {
result, err := ioutil.ReadFile(path)
if(err != nil) {
panic(err)
}
return result
}