本文整理汇总了Golang中github.com/cloudfoundry/gorouter/server.Server类的典型用法代码示例。如果您正苦于以下问题:Golang Server类的具体用法?Golang Server怎么用?Golang Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *ProxySuite) SetUpTest(c *C) {
s.conf = config.DefaultConfig()
s.conf.TraceKey = "my_trace_key"
s.conf.EndpointTimeout = 500 * time.Millisecond
mbus := fakeyagnats.New()
s.r = registry.NewCFRegistry(s.conf, mbus)
fmt.Printf("Config: %#v", s.conf)
s.accessLogFile = new(test_util.FakeFile)
accessLog := access_log.NewFileAndLoggregatorAccessLogger(s.accessLogFile, "localhost:9843", "secret", 42)
go accessLog.Run()
s.p = NewProxy(ProxyArgs{
EndpointTimeout: s.conf.EndpointTimeout,
Ip: s.conf.Ip,
TraceKey: s.conf.TraceKey,
Registry: s.r,
Reporter: nullVarz{},
Logger: accessLog,
})
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
server := server.Server{Handler: s.p}
go server.Serve(ln)
s.proxyServer = ln
}
示例2: SetUpTest
func (s *ProxySuite) SetUpTest(c *C) {
config := config.DefaultConfig()
config.TraceKey = "my_trace_key"
config.EndpointTimeout = 500 * time.Millisecond
mbus := fakeyagnats.New()
s.r = registry.NewRegistry(config, mbus)
s.p = NewProxy(config, s.r, nullVarz{})
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
server := server.Server{Handler: s.p}
go server.Serve(ln)
s.proxyServer = ln
}
示例3: Run
func (r *Router) Run() {
var err error
util.WritePidFile(r.config.Pidfile)
natsMembers := []yagnats.ConnectionProvider{}
for _, info := range r.config.Nats {
natsMembers = append(natsMembers, &yagnats.ConnectionInfo{
Addr: fmt.Sprintf("%s:%d", info.Host, info.Port),
Username: info.User,
Password: info.Pass,
})
}
natsInfo := &yagnats.ConnectionCluster{natsMembers}
for {
err = r.mbusClient.Connect(natsInfo)
if err == nil {
log.Infof("Connected to NATS")
break
}
log.Errorf("Could not connect to NATS: %s", err)
time.Sleep(500 * time.Millisecond)
}
r.RegisterComponent()
// Subscribe register/unregister router
r.SubscribeRegister()
r.HandleGreetings()
r.SubscribeUnregister()
// Kickstart sending start messages
r.SendStartMessage()
// Send start again on reconnect
r.mbusClient.ConnectedCallback = func() {
r.SendStartMessage()
}
// Schedule flushing active app's app_id
r.ScheduleFlushApps()
// Wait for one start message send interval, such that the router's registry
// can be populated before serving requests.
if r.config.StartResponseDelayInterval != 0 {
log.Infof("Waiting %s before listening...", r.config.StartResponseDelayInterval)
time.Sleep(r.config.StartResponseDelayInterval)
}
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", r.config.Port))
if err != nil {
log.Fatalf("net.Listen: %s", err)
}
log.Infof("Listening on %s", listen.Addr())
server := server.Server{Handler: r.proxy}
go func() {
err := server.Serve(listen)
if err != nil {
log.Fatalf("proxy.Serve: %s", err)
}
}()
}