当前位置: 首页>>代码示例>>Golang>>正文


Golang proxy.Server类代码示例

本文整理汇总了Golang中router/proxy.Server的典型用法代码示例。如果您正苦于以下问题:Golang Server类的具体用法?Golang Server怎么用?Golang Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Server类的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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。