本文整理汇总了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)
}
}
示例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)
}
}
示例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)
}
}