本文整理汇总了Golang中github.com/cloudfoundry-incubator/ducati-daemon/executor.Context.ListenerFactory方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.ListenerFactory方法的具体用法?Golang Context.ListenerFactory怎么用?Golang Context.ListenerFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry-incubator/ducati-daemon/executor.Context
的用法示例。
在下文中一共展示了Context.ListenerFactory方法的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
}
示例2:
Describe("SandboxNamespaceRepository", func() {
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()))
})
})
})