-
Notifications
You must be signed in to change notification settings - Fork 0
/
fly_environment.go
55 lines (48 loc) · 1.04 KB
/
fly_environment.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 mermaidlive
import (
"fmt"
"os"
)
func getFlyRegion() string {
if region, ok := os.LookupEnv("FLY_REGION"); ok {
return region
}
return "local"
}
func getFlyPeersDomain() string {
if appName, ok := os.LookupEnv("FLY_APP_NAME"); ok {
return appName + ".internal"
}
return ""
}
func GetCounterDirectory() string {
if counterDirectory, ok := os.LookupEnv("COUNTER_DIRECTORY"); ok {
return counterDirectory
}
return "."
}
func GetReplicasEvent(count int) Event {
return NewEventWithParam("ReplicasActive",
fmt.Sprintf("%d (you are on '%s')", count, getPublicReplicaId()))
}
func getPublicReplicaId() string {
if id, ok := os.LookupEnv("FLY_MACHINE_ID"); ok && len(id) > 5 {
// do not show the full machine ID
return id[len(id)-5:]
}
hostname, err := os.Hostname()
if err == nil {
return hostname
}
return "local"
}
func getPrivateReplicaId() string {
if id, ok := os.LookupEnv("FLY_MACHINE_ID"); ok && len(id) > 5 {
return id
}
hostname, err := os.Hostname()
if err == nil {
return hostname
}
return "local"
}