本文整理匯總了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)
}
}