當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MasterInfo.GetAddress方法代碼示例

本文整理匯總了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)
	}
}
開發者ID:tooooolong,項目名稱:mesos-consul,代碼行數:28,代碼來源:zk.go

示例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))
}
開發者ID:GaizkaRubio,項目名稱:mesos-dns,代碼行數:21,代碼來源:masters.go

示例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
}
開發者ID:jojimt,項目名稱:contrib,代碼行數:21,代碼來源:client.go


注:本文中的github.com/mesos/mesos-go/mesosproto.MasterInfo.GetAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。