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


Golang types.URLs類代碼示例

本文整理匯總了Golang中github.com/coreos/etcd/pkg/types.URLs的典型用法代碼示例。如果您正苦於以下問題:Golang URLs類的具體用法?Golang URLs怎麽用?Golang URLs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了URLs類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: setPeerURLsHeader

// setPeerURLsHeader reports local urls for peer discovery
func setPeerURLsHeader(req *http.Request, urls types.URLs) {
	if urls == nil {
		// often not set in unit tests
		return
	}
	peerURLs := make([]string, urls.Len())
	for i := range urls {
		peerURLs[i] = urls[i].String()
	}
	req.Header.Set("X-PeerURLs", strings.Join(peerURLs, ","))
}
開發者ID:CliffYuan,項目名稱:etcd,代碼行數:12,代碼來源:util.go

示例2: NewMember

func NewMember(name string, peerURLs types.URLs, clusterName string) *member {
	m := &member{
		raftAttributes: raftAttributes{PeerURLs: peerURLs.StringSlice()},
		attributes:     attributes{Name: name},
	}

	var b []byte
	sort.Strings(m.PeerURLs)
	for _, p := range m.PeerURLs {
		b = append(b, []byte(p)...)
	}

	b = append(b, []byte(clusterName)...)

	hash := sha1.Sum(b)
	m.ID = types.ID(binary.BigEndian.Uint64(hash[:8]))
	return m
}
開發者ID:diffoperator,項目名稱:etcd,代碼行數:18,代碼來源:member.go

示例3: newMember

// newMember creates a Member without an ID and generates one based on the
// name, peer URLs. This is used for bootstrapping.
func newMember(name string, peerURLs types.URLs, now *time.Time) *Member {
	m := &Member{Name: name, PeerURLs: peerURLs.StringSlice()}

	b := []byte(m.Name)
	for _, p := range m.PeerURLs {
		b = append(b, []byte(p)...)
	}

	if now != nil {
		b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...)
	}

	hash := sha1.Sum(b)
	m.ID = int64(binary.BigEndian.Uint64(hash[:8]))
	if m.ID < 0 {
		m.ID = m.ID * -1
	}

	return m
}
開發者ID:digideskio,項目名稱:etcd,代碼行數:22,代碼來源:member.go

示例4: NewMember

// newMember creates a Member without an ID and generates one based on the
// name, peer URLs. This is used for bootstrapping/adding new member.
func NewMember(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Member {
	m := &Member{
		RaftAttributes: RaftAttributes{PeerURLs: peerURLs.StringSlice()},
		Attributes:     Attributes{Name: name},
	}

	var b []byte
	sort.Strings(m.PeerURLs)
	for _, p := range m.PeerURLs {
		b = append(b, []byte(p)...)
	}

	b = append(b, []byte(clusterName)...)
	if now != nil {
		b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...)
	}

	hash := sha1.Sum(b)
	m.ID = binary.BigEndian.Uint64(hash[:8])
	return m
}
開發者ID:ericcapricorn,項目名稱:etcd,代碼行數:23,代碼來源:member.go


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