func()

in runtime/gateway.go [293:362]


func (gateway *Gateway) Bootstrap() error {
	env := gateway.Config.MustGetString("env")

	// start HTTP server
	gateway.RootScope.Counter("server.bootstrap").Inc(1)
	_, err := gateway.localHTTPServer.JustListen()
	if err != nil {
		gateway.Logger.Error("Error listening on port", zap.Error(err))
		return errors.Wrap(err, "error listening on port")
	}
	if gateway.localHTTPServer.RealIP != gateway.httpServer.RealIP && env != testenv {
		_, err := gateway.httpServer.JustListen()
		if err != nil {
			gateway.Logger.Error("Error listening on port", zap.Error(err))
			return errors.Wrap(err, "error listening on port")
		}
	} else {
		// Do not start at the same IP
		gateway.httpServer = gateway.localHTTPServer
	}
	gateway.RealHTTPPort = gateway.httpServer.RealPort
	gateway.RealHTTPAddr = gateway.httpServer.RealAddr

	gateway.WaitGroup.Add(1)
	go gateway.httpServer.JustServe(gateway.WaitGroup)

	if gateway.httpServer != gateway.localHTTPServer {
		gateway.WaitGroup.Add(1)
		go gateway.localHTTPServer.JustServe(gateway.WaitGroup)
	}

	// start TChannel server
	ip := localhost
	if gateway.Config.ContainsKey("tchannel.server.ip") {
		ip = gateway.Config.MustGetString("tchannel.server.ip")
	} else if env != testenv {
		tchannelIP, err := tchannel.ListenIP()
		if err != nil {
			return errors.Wrap(err, "error finding the best IP for tchannel")
		}
		ip = tchannelIP.String()
	}
	tchannelAddr := ip + ":" + strconv.Itoa(int(gateway.TChannelPort))
	ln, err := net.Listen("tcp", tchannelAddr)
	if err != nil {
		gateway.Logger.Error("Error listening tchannel port", zap.Error(err))
		return err
	}
	gateway.RealTChannelAddr = ln.Addr().String()
	gateway.RealTChannelPort = int32(ln.Addr().(*net.TCPAddr).Port)

	// tchannel serve does not block, connection handling is done in different goroutine
	err = gateway.tchannelServer.Serve(ln)
	if err != nil {
		gateway.Logger.Error("Error starting tchannel server", zap.Error(err))
		return err
	}

	gateway.RootScope.Counter("startup.success").Inc(1)

	if gateway.GRPCClientDispatcher != nil {
		err = gateway.GRPCClientDispatcher.Start()
		if err != nil {
			gateway.Logger.Error("error starting gRPC client dispatcher", zap.Error(err))
			return err
		}
	}

	return nil
}