-
Notifications
You must be signed in to change notification settings - Fork 19
/
env.go
104 lines (89 loc) · 2.42 KB
/
env.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package context
import (
"fmt"
"os"
"github.com/baetyl/baetyl-go/v2/errors"
)
// All keys
const (
KeyBaetyl = "BAETYL"
KeyConfFile = "BAETYL_CONF_FILE"
KeyNodeName = "BAETYL_NODE_NAME"
KeyAppName = "BAETYL_APP_NAME"
KeyAppVersion = "BAETYL_APP_VERSION"
KeySvcName = "BAETYL_SERVICE_NAME"
KeySysConf = "BAETYL_SYSTEM_CONF"
KeyRunMode = "BAETYL_RUN_MODE"
KeyServiceDynamicPort = "BAETYL_SERVICE_DYNAMIC_PORT"
KeyBaetylHostPathLib = "BAETYL_HOST_PATH_LIB"
)
const (
RunModeKube = "kube"
RunModeNative = "native"
)
const (
baetylEdgeNamespace = "baetyl-edge"
baetylEdgeSystemNamespace = "baetyl-edge-system"
baetylBrokerSystemPort = "50010"
baetylFunctionSystemHttpPort = "50011"
baetylFunctionSystemGrpcPort = "50012"
defaultHostPathLib = "/var/lib/baetyl"
)
// HostPathLib return HostPathLib
func HostPathLib() (string, error) {
var hostPathLib string
if val := os.Getenv(KeyBaetylHostPathLib); val == "" {
err := os.Setenv(KeyBaetylHostPathLib, defaultHostPathLib)
if err != nil {
return "", errors.Trace(err)
}
hostPathLib = defaultHostPathLib
} else {
hostPathLib = val
}
return hostPathLib, nil
}
// RunMode return run mode of edge.
func RunMode() string {
mode := os.Getenv(KeyRunMode)
if mode != RunModeNative {
mode = RunModeKube
}
return mode
}
// EdgeNamespace return namespace of edge.
func EdgeNamespace() string {
return baetylEdgeNamespace
}
// EdgeSystemNamespace return system namespace of edge.
func EdgeSystemNamespace() string {
return baetylEdgeSystemNamespace
}
// BrokerPort return broker port.
func BrokerPort() string {
return baetylBrokerSystemPort
}
// FunctionPort return http port of function.
func FunctionHttpPort() string {
return baetylFunctionSystemHttpPort
}
// BrokerHost return broker host.
func BrokerHost() string {
if RunMode() == RunModeNative {
return "127.0.0.1"
}
return fmt.Sprintf("%s.%s", "baetyl-broker", baetylEdgeSystemNamespace)
}
// FunctionHost return function host.
func FunctionHost() string {
if RunMode() == RunModeNative {
return "127.0.0.1"
}
return fmt.Sprintf("%s.%s", "baetyl-function", baetylEdgeSystemNamespace)
}
func getBrokerAddress() string {
return fmt.Sprintf("%s://%s:%s", "ssl", BrokerHost(), BrokerPort())
}
func getFunctionAddress() string {
return fmt.Sprintf("%s://%s:%s", "https", FunctionHost(), FunctionHttpPort())
}