-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
61 lines (56 loc) · 1.01 KB
/
Copy pathutils.go
File metadata and controls
61 lines (56 loc) · 1.01 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
59
60
61
package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
func normalizeTimestamp(ts any) string {
switch v := ts.(type) {
case time.Time:
if v.IsZero() {
return time.Now().UTC().Format(time.RFC3339Nano)
}
return v.UTC().Format(time.RFC3339Nano)
case string:
if v == "" {
return time.Now().UTC().Format(time.RFC3339Nano)
}
return v
default:
s := fmt.Sprint(ts)
if s == "" || s == "<nil>" {
return time.Now().UTC().Format(time.RFC3339Nano)
}
return s
}
}
func snowflakeGreater(a, b string) bool {
if b == "" {
return a != ""
}
au, errA := strconv.ParseUint(a, 10, 64)
bu, errB := strconv.ParseUint(b, 10, 64)
if errA != nil || errB != nil {
return a > b
}
return au > bu
}
func getenvDefault(k, def string) string {
if v := os.Getenv(k); v != "" {
return v
}
return def
}
func getenvBoolDefault(k string, def bool) bool {
v := strings.TrimSpace(os.Getenv(k))
if v == "" {
return def
}
b, err := strconv.ParseBool(v)
if err != nil {
return def
}
return b
}