forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
45 lines (40 loc) · 934 Bytes
/
common.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
package agollo
import (
"fmt"
"net"
"net/url"
)
func getLocalIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
for _, a := range addrs {
if ip4 := toIP4(a); ip4 != nil {
return ip4.String()
}
}
return ""
}
func toIP4(addr net.Addr) net.IP {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
return ipnet.IP.To4()
}
return nil
}
func notificationURL(conf *Conf, notifications string) string {
return fmt.Sprintf("http://%s/notifications/v2?appId=%s&cluster=%s¬ifications=%s",
conf.IP,
url.QueryEscape(conf.AppID),
url.QueryEscape(conf.Cluster),
url.QueryEscape(notifications))
}
func configURL(conf *Conf, namespace, releaseKey string) string {
return fmt.Sprintf("http://%s/configs/%s/%s/%s?releaseKey=%s&ip=%s",
conf.IP,
url.QueryEscape(conf.AppID),
url.QueryEscape(conf.Cluster),
url.QueryEscape(namespace),
releaseKey,
getLocalIP())
}