本文整理匯總了Golang中github.com/mesos/mesos-go/mesosproto.MasterInfo.GetAddress方法的典型用法代碼示例。如果您正苦於以下問題:Golang MasterInfo.GetAddress方法的具體用法?Golang MasterInfo.GetAddress怎麽用?Golang MasterInfo.GetAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mesos/mesos-go/mesosproto.MasterInfo
的用法示例。
在下文中一共展示了MasterInfo.GetAddress方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MasterInfoToMesosHost
func MasterInfoToMesosHost(mi *proto.MasterInfo) *MesosHost {
if mi == nil {
return &MesosHost{
Host: "",
Ip: "",
Port: 0,
PortString: "",
IsLeader: false,
IsRegistered: false,
}
}
addr := mi.GetAddress()
if addr.GetHostname() != "" {
return &MesosHost{
Host: addr.GetHostname(),
Ip: addr.GetIp(),
Port: int(addr.GetPort()),
PortString: fmt.Sprintf("%d", addr.GetPort()),
IsLeader: false,
IsRegistered: false,
}
} else {
log.Debug("Using old protobuf format")
// Old protobuf format
return ProtoBufToMesosHost(mi)
}
}
示例2: masterAddr
// masterAddr returns an address (ip:port) from the given *mesos.MasterInfo or
// an empty string if it nil.
//
// BUG(tsenart): The byte order of the `ip` field in MasterInfo is platform
// dependent. We assume that Mesos is compiled with the same architecture as
// Mesos-DNS and hence same byte order. If this isn't the case, the address
// returned will be wrong. This only affects Mesos versions < 0.24.0
func masterAddr(info *mesos.MasterInfo) string {
if info == nil {
return ""
}
ip, port := "", int64(0)
if addr := info.GetAddress(); addr != nil { // Mesos >= 0.24.0
ip, port = addr.GetIp(), int64(addr.GetPort())
} else { // Mesos < 0.24.0
ipv4 := make([]byte, net.IPv4len)
byteOrder.PutUint32(ipv4, info.GetIp())
ip, port = net.IP(ipv4).String(), int64(info.GetPort())
}
return net.JoinHostPort(ip, strconv.FormatInt(port, 10))
}
示例3: extractMasterAddress
func extractMasterAddress(info *mesos.MasterInfo) (host string, port int) {
if info != nil {
host = info.GetAddress().GetHostname()
if host == "" {
host = info.GetAddress().GetIp()
}
if host != "" {
// use port from Address
port = int(info.GetAddress().GetPort())
} else {
// deprecated: get host and port directly from MasterInfo (and not Address)
host = info.GetHostname()
if host == "" {
host = unpackIPv4(info.GetIp())
}
port = int(info.GetPort())
}
}
return
}