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


Golang Context.DNSServerFactory方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/ducati-daemon/executor.Context.DNSServerFactory方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.DNSServerFactory方法的具體用法?Golang Context.DNSServerFactory怎麽用?Golang Context.DNSServerFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/ducati-daemon/executor.Context的用法示例。


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

示例1: Execute

func (sd StartDNSServer) Execute(context executor.Context) error {
	listenerFactory := context.ListenerFactory()

	listenAddress, err := net.ResolveUDPAddr("udp", sd.ListenAddress)
	if err != nil {
		return fmt.Errorf("resolve udp address: %s", err)
	}

	sbox, err := context.SandboxRepository().Get(sd.SandboxName)
	if err != nil {
		return fmt.Errorf("get sandbox: %s", err)
	}

	sbox.Lock()
	defer sbox.Unlock()

	namespace := sbox.Namespace()

	var conn *net.UDPConn
	err = namespace.Execute(func(*os.File) error {
		linkFactory := context.LinkFactory()
		err := linkFactory.CreateDummy(DNS_INTERFACE_NAME)
		if err != nil {
			return fmt.Errorf("create dummy: %s", err)
		}

		dnsAddress := &net.IPNet{
			IP:   listenAddress.IP,
			Mask: net.CIDRMask(32, 32),
		}

		err = context.AddressManager().AddAddress(DNS_INTERFACE_NAME, dnsAddress)
		if err != nil {
			return fmt.Errorf("add address: %s", err)
		}

		err = linkFactory.SetUp(DNS_INTERFACE_NAME)
		if err != nil {
			return fmt.Errorf("set up: %s", err)
		}

		conn, err = listenerFactory.ListenUDP("udp", listenAddress)
		if err != nil {
			return fmt.Errorf("listen udp: %s", err)
		}

		return nil
	})
	if err != nil {
		return fmt.Errorf("namespace execute: %s", err)
	}

	dnsServerRunner := context.DNSServerFactory().New(conn, namespace)

	err = sbox.LaunchDNS(dnsServerRunner)
	if err != nil {
		return fmt.Errorf("sandbox launch dns: %s", err)
	}

	return nil
}
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:61,代碼來源:start_dns_server.go

示例2:

			It("returns the SandboxNamespaceRepository", func() {
				Expect(context.SandboxNamespaceRepository()).To(Equal(sandboxNamespaceRepository))
			})
		})

		Describe("SandboxRepository", func() {
			It("returns the SandboxRepository", func() {
				Expect(context.SandboxRepository()).To(Equal(sandboxRepository))
			})
		})

		Describe("ListenerFactory", func() {
			It("returns the ListenerFactory", func() {
				Expect(context.ListenerFactory()).To(Equal(listenerFactory))
			})
		})

		Describe("DNSServerFactory", func() {
			It("returns the DNSServerFactory", func() {
				Expect(context.DNSServerFactory()).To(Equal(dnsServerFactory))
			})
		})

		Describe("Logger", func() {
			It("returns the Logger with a new session", func() {
				Expect(context.Logger().SessionName()).NotTo(Equal(logger.SessionName()))
			})
		})
	})
})
開發者ID:cloudfoundry-incubator,項目名稱:ducati-daemon,代碼行數:30,代碼來源:executor_test.go


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