forked from knative/eventing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
35 lines (28 loc) · 936 Bytes
/
util.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
package util
import (
"fmt"
"os"
eventingutils "github.com/knative/eventing/pkg/utils"
)
const (
// DefaultNatssURLKey is the environment variable that can be set to specify the natss url
defaultNatssURLVar = "DEFAULT_NATSS_URL"
defaultClusterIDVar = "DEFAULT_CLUSTER_ID"
fallbackDefaultNatssURLTmpl = "nats://nats-streaming.natss.svc.%s:4222"
fallbackDefaultClusterID = "knative-nats-streaming"
)
// GetDefaultNatssURL returns the default natss url to connect to
func GetDefaultNatssURL() string {
return getEnv(defaultNatssURLVar, fmt.Sprintf(fallbackDefaultNatssURLTmpl, eventingutils.GetClusterDomainName()))
}
// GetDefaultClusterID returns the default cluster id to connect with
func GetDefaultClusterID() string {
return getEnv(defaultClusterIDVar, fallbackDefaultClusterID)
}
func getEnv(envKey string, fallback string) string {
val, ok := os.LookupEnv(envKey)
if !ok {
return fallback
}
return val
}