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


Golang etchosts.Build函數代碼示例

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


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

示例1: buildHostsFiles

func (ep *endpoint) buildHostsFiles() error {
	var extraContent []etchosts.Record

	ep.Lock()
	container := ep.container
	joinInfo := ep.joinInfo
	ifaces := ep.iFaces
	ep.Unlock()

	if container == nil {
		return ErrNoContainer{}
	}

	if container.config.hostsPath == "" {
		container.config.hostsPath = defaultPrefix + "/" + container.id + "/hosts"
	}

	dir, _ := filepath.Split(container.config.hostsPath)
	err := createBasePath(dir)
	if err != nil {
		return err
	}

	if joinInfo != nil && joinInfo.hostsPath != "" {
		content, err := ioutil.ReadFile(joinInfo.hostsPath)
		if err != nil && !os.IsNotExist(err) {
			return err
		}

		if err == nil {
			return ioutil.WriteFile(container.config.hostsPath, content, 0644)
		}
	}

	name := container.config.hostName
	if container.config.domainName != "" {
		name = name + "." + container.config.domainName
	}

	for _, extraHost := range container.config.extraHosts {
		extraContent = append(extraContent,
			etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
	}

	IP := ""
	if len(ifaces) != 0 && ifaces[0] != nil {
		IP = ifaces[0].addr.IP.String()
	}

	return etchosts.Build(container.config.hostsPath, IP, container.config.hostName,
		container.config.domainName, extraContent)
}
開發者ID:AlphaStaxLLC,項目名稱:libnetwork,代碼行數:52,代碼來源:endpoint.go

示例2: updateHostsFile

func (sb *sandbox) updateHostsFile(ifaceIP string, svcRecords []etchosts.Record) error {
	// Rebuild the hosts file accounting for the passed interface IP and service records
	extraContent := make([]etchosts.Record, 0, len(sb.config.extraHosts)+len(svcRecords))

	for _, extraHost := range sb.config.extraHosts {
		extraContent = append(extraContent, etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
	}

	for _, svc := range svcRecords {
		extraContent = append(extraContent, svc)
	}

	return etchosts.Build(sb.config.hostsPath, ifaceIP, sb.config.hostName, sb.config.domainName, extraContent)
}
開發者ID:hurrygeek,項目名稱:libnetwork,代碼行數:14,代碼來源:sandbox.go

示例3: updateHostsFile

func (sb *sandbox) updateHostsFile(ifaceIP string, svcRecords []etchosts.Record) error {
	var err error

	if sb.config.originHostsPath != "" {
		return nil
	}

	max := func(a, b int) int {
		if a < b {
			return b
		}

		return a
	}

	extraContent := make([]etchosts.Record, 0,
		max(len(sb.config.extraHosts), len(svcRecords)))

	sb.hostsOnce.Do(func() {
		// Rebuild the hosts file accounting for the passed
		// interface IP and service records

		for _, extraHost := range sb.config.extraHosts {
			extraContent = append(extraContent,
				etchosts.Record{Hosts: extraHost.name, IP: extraHost.IP})
		}

		err = etchosts.Build(sb.config.hostsPath, ifaceIP,
			sb.config.hostName, sb.config.domainName, extraContent)
	})

	if err != nil {
		return err
	}

	extraContent = extraContent[:0]
	for _, svc := range svcRecords {
		extraContent = append(extraContent, svc)
	}

	sb.addHostsEntries(extraContent)
	return nil
}
開發者ID:masa-ike,項目名稱:docker,代碼行數:43,代碼來源:sandbox.go


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