-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
58 lines (52 loc) · 1.02 KB
/
utils.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
package notifier
import (
"context"
"github.com/carousell/go-logging"
"os"
"reflect"
"strconv"
)
var (
serverRoot string
hostname string
)
func ParseRawData(ctx context.Context, rawData ...interface{}) (extraData map[string]interface{}, tagData []map[string]string) {
extraData = make(map[string]interface{})
for pos := range rawData {
data := rawData[pos]
if _, ok := data.(context.Context); ok {
continue
}
if tags, ok := data.(isTags); ok {
tagData = append(tagData, tags.value())
} else {
extraData[reflect.TypeOf(data).String()+strconv.Itoa(pos)] = data
}
}
if logFields := logging.FromContext(ctx); logFields != nil {
for k, v := range logFields {
extraData[k] = v
}
}
return
}
func GetHostname() string {
if hostname != "" {
return hostname
}
name, err := os.Hostname()
if err == nil {
hostname = name
}
return hostname
}
func GetServerRoot() string {
if serverRoot != "" {
return serverRoot
}
cwd, err := os.Getwd()
if err == nil {
serverRoot = cwd
}
return serverRoot
}