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


Golang Server.Serve方法代碼示例

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


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

示例1: Run

func (r *Router) Run() {
	var err error

	// Subscribe register/unregister router
	r.SubscribeRegister()
	r.SubscribeUnregister()

	// Kickstart sending start messages
	r.SendStartMessage()

	// Schedule flushing active app's app_id
	r.ScheduleFlushApps()

	l, err := net.Listen("tcp", fmt.Sprintf(":%d", r.config.Port))
	if err != nil {
		log.Fatalf("net.Listen: %s", err)
	}

	// Wait for one start message send interval, such that the router's registry
	// can be populated before serving requests.
	if r.config.PublishStartMessageInterval != 0 {
		log.Infof("Waiting %s before listening...", r.config.PublishStartMessageInterval)
		time.Sleep(r.config.PublishStartMessageInterval)
	}

	log.Infof("Listening on %s", l.Addr())

	s := proxy.Server{Handler: r.proxy}

	err = s.Serve(l)
	if err != nil {
		log.Fatalf("proxy.Serve: %s", err)
	}
}
開發者ID:hfeeki,項目名稱:gorouter,代碼行數:34,代碼來源:router.go

示例2: Run

func (router *Router) Run() {
	var err error
	go func() {
		for {
			err = router.mbusClient.Connect()
			if err == nil {
				break
			}
			log.Errorf("Could not connect to NATS: ", err.Error())
			time.Sleep(500 * time.Millisecond)
		}
	}()

	router.RegisterComponent()

	// Kickstart sending start messages
	router.SendStartMessage()

	// Subscribe register/unregister router
	router.SubscribeRegister()
	router.SubscribeUnregister()

	// Schedule flushing active app's app_id
	router.ScheduleFlushApps()

	// Wait for one start message send interval, such that the router's registry
	// can be populated before serving requests.
	if router.config.PublishStartMessageInterval != 0 {
		log.Infof("Waiting %s before listening...", router.config.PublishStartMessageInterval)
		time.Sleep(router.config.PublishStartMessageInterval)
	}

	listen, err := net.Listen("tcp", fmt.Sprintf(":%d", router.config.Port))
	if err != nil {
		log.Fatalf("net.Listen: %s", err)
	}

	util.WritePidFile(router.config.Pidfile)

	log.Infof("Listening on %s", listen.Addr())

	server := proxy.Server{Handler: router.proxy}

	err = server.Serve(listen)
	if err != nil {
		log.Fatalf("proxy.Serve: %s", err)
	}
}
開發者ID:vito,項目名稱:gorouter,代碼行數:48,代碼來源:router.go

示例3: Run

func (r *Router) Run() {
	var err error

	// Subscribe register/unregister router
	r.SubscribeRegister()
	r.SubscribeUnregister()
	r.SubscribeStatus()
	// Kickstart sending start messages
	r.SendStartMessage()

	// Schedule flushing active app's app_id
	r.ScheduleFlushApps()
	fmt.Printf("available cpu =  %d \n", runtime.NumCPU())
	//runtime.GOMAXPROCS(2)

	// Wait for one start message send interval, such that the router's registry
	// can be populated before serving requests.
	if r.config.PublishStartMessageInterval != 0 {
		log.Infof("Waiting %s before listening...", r.config.PublishStartMessageInterval)
		time.Sleep(r.config.PublishStartMessageInterval)
	}
	fmt.Printf(":%d \n", r.config.Port)
	l, err := net.Listen("tcp", fmt.Sprintf(":%d", r.config.Port))
	if err != nil {
		log.Fatalf("net.Listen: %s", err)
	}

	util.WritePidFile(r.config.Pidfile)

	log.Infof("Listening on %s", l.Addr())

	s := proxy.Server{Handler: r.proxy} // 這裏的proxy? Server??

	err = s.Serve(l) //這裏估計也是一個死循環?
	if err != nil {
		log.Fatalf("proxy.Serve: %s", err)
	}

}
開發者ID:ndzj081221130,項目名稱:router-src,代碼行數:39,代碼來源:router.go


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