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


Golang cluster.Cluster類代碼示例

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


在下文中一共展示了Cluster類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
開發者ID:abhishekamralkar,項目名稱:swarm,代碼行數:28,代碼來源:api.go

示例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
}
開發者ID:SivagnanamCiena,項目名稱:swarm,代碼行數:54,代碼來源:server.go

示例3: NewPrimary

// NewPrimary creates a new API router.
func NewPrimary(cluster cluster.Cluster, tlsConfig *tls.Config, status StatusHandler, enableCors bool) *mux.Router {
	// Register the API events handler in the cluster.
	eventsHandler := newEventsHandler()
	cluster.RegisterEventHandler(eventsHandler)

	context := &context{
		cluster:       cluster,
		eventsHandler: eventsHandler,
		statusHandler: status,
		tlsConfig:     tlsConfig,
	}

	r := mux.NewRouter()
	for method, mappings := range routes {
		for route, fct := range mappings {
			log.WithFields(log.Fields{"method": method, "route": route}).Debug("Registering HTTP route")

			localRoute := route
			localFct := fct
			wrap := func(w http.ResponseWriter, r *http.Request) {
				log.WithFields(log.Fields{"method": r.Method, "uri": r.RequestURI}).Debug("HTTP request received")
				if enableCors {
					writeCorsHeaders(w, r)
				}
				localFct(context, w, r)
			}
			localMethod := method

			r.Path("/v{version:[0-9.]+}" + localRoute).Methods(localMethod).HandlerFunc(wrap)
			r.Path(localRoute).Methods(localMethod).HandlerFunc(wrap)
		}
	}

	return r
}
開發者ID:konder,項目名稱:swarm,代碼行數:36,代碼來源:primary.go

示例4: 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()
}
開發者ID:cuulee,項目名稱:swarm,代碼行數:18,代碼來源:api.go

示例5: run

func run(cl cluster.Cluster, candidate *leadership.Candidate, server *api.Server, primary *mux.Router, replica *api.Replica) {
	electedCh, errCh := candidate.RunForElection()
	var watchdog *cluster.Watchdog
	for {
		select {
		case isElected := <-electedCh:
			if isElected {
				log.Info("Leader Election: Cluster leadership acquired")
				watchdog = cluster.NewWatchdog(cl)
				server.SetHandler(primary)
			} else {
				log.Info("Leader Election: Cluster leadership lost")
				cl.UnregisterEventHandler(watchdog)
				server.SetHandler(replica)
			}

		case err := <-errCh:
			log.Error(err)
			return
		}
	}
}
開發者ID:yehohanan7,項目名稱:swarm,代碼行數:22,代碼來源:manage.go

示例6: NewPrimary

// NewPrimary creates a new API router.
func NewPrimary(cluster cluster.Cluster, tlsConfig *tls.Config, status StatusHandler, debug, enableCors bool) *mux.Router {
	// Register the API events handler in the cluster.
	eventsHandler := newEventsHandler()
	cluster.RegisterEventHandler(eventsHandler)

	context := &context{
		cluster:       cluster,
		eventsHandler: eventsHandler,
		statusHandler: status,
		tlsConfig:     tlsConfig,
	}

	r := mux.NewRouter()
	setupPrimaryRouter(r, context, enableCors)

	if debug {
		profilerSetup(r, "/debug/")
	}

	return r
}
開發者ID:cbbs,項目名稱:swarm,代碼行數:22,代碼來源:primary.go


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