本文整理匯總了Golang中github.com/docker/swarm/cluster.Cluster.Events方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cluster.Events方法的具體用法?Golang Cluster.Events怎麽用?Golang Cluster.Events使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarm/cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.Events方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListenAndServe
func ListenAndServe(c *cluster.Cluster, s *scheduler.Scheduler, addr, version string, enableCors bool, tlsConfig *tls.Config) error {
context := &context{
cluster: c,
scheduler: s,
version: version,
eventsHandler: NewEventsHandler(),
}
c.Events(context.eventsHandler)
r, err := createRouter(context, enableCors)
if err != nil {
return err
}
server := &http.Server{
Addr: addr,
Handler: r,
}
l, err := net.Listen("tcp", addr)
if err != nil {
return err
}
if tlsConfig != nil {
tlsConfig.NextProtos = []string{"http/1.1"}
l = tls.NewListener(l, tlsConfig)
}
return server.Serve(l)
}
示例2: ListenAndServe
func ListenAndServe(c *cluster.Cluster, s *scheduler.Scheduler, hosts []string, enableCors bool, tlsConfig *tls.Config) error {
context := &context{
cluster: c,
scheduler: s,
eventsHandler: NewEventsHandler(),
tlsConfig: tlsConfig,
}
c.Events(context.eventsHandler)
r := createRouter(context, enableCors)
chErrors := make(chan error, len(hosts))
for _, host := range hosts {
protoAddrParts := strings.SplitN(host, "://", 2)
if len(protoAddrParts) == 1 {
protoAddrParts = append([]string{"tcp"}, protoAddrParts...)
}
go func() {
log.WithFields(log.Fields{"proto": protoAddrParts[0], "addr": protoAddrParts[1]}).Info("Listening for HTTP")
var (
l net.Listener
err error
server = &http.Server{
Addr: protoAddrParts[1],
Handler: r,
}
)
switch protoAddrParts[0] {
case "unix":
l, err = newUnixListener(protoAddrParts[1], tlsConfig)
case "tcp":
l, err = newListener("tcp", protoAddrParts[1], tlsConfig)
default:
err = fmt.Errorf("unsupported protocol: %q", protoAddrParts[0])
}
if err != nil {
chErrors <- err
} else {
chErrors <- server.Serve(l)
}
}()
}
for i := 0; i < len(hosts); i++ {
err := <-chErrors
if err != nil {
return err
}
}
return nil
}
示例3: ListenAndServe
func ListenAndServe(c *cluster.Cluster, s *scheduler.Scheduler, addr, version string, enableCors bool) error {
context := &context{
cluster: c,
scheduler: s,
version: version,
eventsHandler: NewEventsHandler(),
}
c.Events(context.eventsHandler)
r, err := createRouter(context, enableCors)
if err != nil {
return err
}
server := &http.Server{
Addr: addr,
Handler: r,
}
return server.ListenAndServe()
}