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


Golang Server.Serve方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/gorouter/server.Server.Serve方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Serve方法的具体用法?Golang Server.Serve怎么用?Golang Server.Serve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/gorouter/server.Server的用法示例。


在下文中一共展示了Server.Serve方法的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
}
开发者ID:nimbus-cloud,项目名称:gorouter,代码行数:33,代码来源:proxy_test.go

示例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
}
开发者ID:karlpilkington,项目名称:golang-devops-stuff,代码行数:19,代码来源:proxy_test.go

示例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)
		}
	}()
}
开发者ID:BrianMMcClain,项目名称:gorouter,代码行数:70,代码来源:router.go


注:本文中的github.com/cloudfoundry/gorouter/server.Server.Serve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。