-
Notifications
You must be signed in to change notification settings - Fork 26
/
util.go
68 lines (56 loc) · 1.73 KB
/
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
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
package plugins
import (
"fmt"
"os"
)
// RSUtil will contain uril methods for
// working with RS internally.
type RSUtil struct {
}
// RSUtilInstance will return single instance for RSUtil
// This should be the only access for the RSUtil Instance
func RSUtilInstance() *RSUtil {
rsUtilOnce.Do(func() { singletonRSUtil = &RSUtil{} })
return singletonRSUtil
}
// URL will expose the RS Url for the current
// instance.
func (rsUtil *RSUtil) URL(withCredentials bool) string {
ssl := "http"
if rsUtil.IsHttps() {
ssl += "s"
}
url := fmt.Sprint(ssl, "://")
if withCredentials {
url += fmt.Sprint(rsUtil.MasterCredentials(), "@")
}
return fmt.Sprintf("%s%s:%d", url, rsUtil.Address(), rsUtil.Port())
}
// Port will return the RS Port for the current instance
func (rsUtil *RSUtil) Port() int {
healthCheckInstance := rsUtil.getHealthInstance()
return *healthCheckInstance.port
}
// Address will return the RS Address for the current instance
func (rsUtil *RSUtil) Address() string {
healthCheckInstance := rsUtil.getHealthInstance()
return *healthCheckInstance.address
}
// IsHttps will return whether or not SSL is being used
func (rsUtil *RSUtil) IsHttps() bool {
healthCheckInstance := rsUtil.getHealthInstance()
return *healthCheckInstance.isHttps
}
// MasterCredentials will return the master credentials for
// the current instance in the username:password format.
func (rsUtil *RSUtil) MasterCredentials() string {
username, password := os.Getenv("USERNAME"), os.Getenv("PASSWORD")
if username == "" {
username, password = "foo", "bar"
}
return username + ":" + password
}
// getHealthInstance will return the health instance
func (rsUtil *RSUtil) getHealthInstance() *RouterHealthCheck {
return RouterHealthCheckInstance()
}