-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspew.go
55 lines (46 loc) · 930 Bytes
/
spew.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
package main
import (
"fmt"
"os"
"strings"
"time"
)
func main() {
// init
fmt.Println("Spewing...")
// output vars
if os.Getenv("SPEW_ENV") != "" {
for _, env := range os.Environ() {
fmt.Println(" ==> " + env)
}
}
// input
spewPre := "spew"
if len(os.Args) > 1 {
spewPre = os.Args[1]
}
// force fail
if os.Getenv("SPEW_FAIL") != "" {
if strings.ToUpper(os.Getenv("SPEW_FAIL")) == "TRUE" {
os.Exit(1)
}
}
// settings
spewOut := "spew"
if os.Getenv("SPEW_OUT") != "" {
spewOut = os.Getenv("SPEW_OUT")
}
spewInterval := "5s"
if os.Getenv("SPEW_INTERVAL") != "" {
spewInterval = os.Getenv("SPEW_INTERVAL")
}
spewTimespan, err := time.ParseDuration(spewInterval)
if err != nil {
fmt.Println("ERROR: Cannot interpret SPEW_INTERVAL " + err.Error())
}
// loop
for {
fmt.Println(time.Now().Format(time.RFC3339) + " [" + spewPre + "] " + spewOut)
time.Sleep(spewTimespan)
}
}