-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
45 lines (34 loc) · 747 Bytes
/
util.go
File metadata and controls
45 lines (34 loc) · 747 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
package gocommon
import (
"context"
"fmt"
"os"
"strings"
)
func CreateContext() context.Context {
ctx := context.WithValue(context.TODO(), LoggerKey, CreateLogger())
return ctx
}
func IsDocker() bool {
_, err := os.Stat("/.dockerenv")
return !os.IsNotExist(err)
}
func GetEnvWithDefault(key string, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}
func GetBoolEnvWithDefault(key string, defaultValue bool) bool {
value := strings.ToLower(os.Getenv(key))
if value == "" {
return defaultValue
}
return value == "true"
}
func RecoverFunction(funcName string) {
if r := recover(); r != nil {
println("[panic] " + funcName + ": " + fmt.Sprintf("%s", r))
}
}