-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
50 lines (40 loc) · 773 Bytes
/
utils.go
File metadata and controls
50 lines (40 loc) · 773 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
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"io/fs"
"io/ioutil"
"log"
"os"
"strings"
)
func CheckErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func GetRootDomain(fqdn string) (str string) {
arr := strings.Split(fqdn, ".")
max := len(arr)
str = fmt.Sprintf("%s.%s", arr[max-2], arr[max-1])
return str
}
func ReadFile(path string) string {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return ""
}
data, err := ioutil.ReadFile(path)
CheckErr(err)
return string(data)
}
func WriteFile(path string, content string) {
err := ioutil.WriteFile(path, []byte(content), 0700)
CheckErr(err)
}
func CreateFolderIfNotExists(path string, mode fs.FileMode) error {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return os.Mkdir(path, mode)
}
return nil
}