-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (54 loc) · 1.48 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"log"
"os"
"time"
)
func main() {
start := time.Now()
c := time.Now().UTC().String()
filename := "test.txt"
var testfolder string
if os.Getenv("DP_TEST_FOLDER") == "" {
testfolder = "./"
} else {
testfolder = os.Getenv("DP_TEST_FOLDER")
}
createFile := testfolder + filename
log.Println("folder:", testfolder)
log.Println("file:", createFile)
/* Folder create */
if _, err := os.Stat(testfolder); os.IsNotExist(err) {
// path/to/whatever does not exist
err := os.MkdirAll(testfolder, os.ModePerm)
if err != nil {
log.Println(err)
time.Sleep(time.Second * 3)
panic("😩 File system not ready: folder failure: will exit to retry")
}
log.Println("Created directory: ", testfolder)
} else {
log.Println("Directory exists: ", testfolder)
}
/* Write check. */
err := os.WriteFile(createFile, []byte(c), 0644)
if err != nil {
log.Println(err)
time.Sleep(time.Second * 3)
panic("😩 File system not ready: write failure: will exit to retry")
}
/* Read check. */
dat, err := os.ReadFile(createFile)
if err != nil {
log.Println(err)
time.Sleep(time.Second * 3)
panic("😩 File system not ready: read failure: will exit to retry")
}
if string(dat) != c {
time.Sleep(time.Second * 3)
panic("😩 File system not ready: read write check failure: will exit to retry")
}
stop := time.Now()
log.Println("File system ready", string(dat), fmt.Sprintf("%f", float32(stop.Sub(start))/float32(time.Millisecond))+"ms")
}