func runHTTPServer()

in server/cmd/harp-server/internal/cmd/http.go [56:109]


func runHTTPServer(cmd *cobra.Command, args []string) {
	ctx, cancel := context.WithCancel(cmd.Context())
	defer cancel()

	// Initialize config
	initConfig()

	// Starting banner
	log.For(ctx).Info("Starting harp HTTP bundle server ...")

	// Start goroutine group
	err := platform.Serve(ctx, &platform.Server{
		Debug:           conf.Debug.Enable,
		Name:            "harp-server-http",
		Version:         version.Version,
		Revision:        version.Commit,
		Instrumentation: conf.Instrumentation,
		Network:         conf.HTTP.Network,
		Address:         conf.HTTP.Listen,
		Builder: func(ln net.Listener, group *run.Group) {
			// Override config
			if err := overrideBackendConfig(conf, httpNamespaces); err != nil {
				log.For(ctx).Fatal("Unable to parse namespace mapping", zap.Error(err))
			}

			server, err := http.New(ctx, conf)
			if err != nil {
				log.For(ctx).Fatal("Unable to start HTTP server", zap.Error(err))
			}

			group.Add(
				func() error {
					if conf.HTTP.UseTLS {
						log.For(ctx).Info("Starting HTTPS server", zap.Stringer("address", ln.Addr()))
						return server.ServeTLS(ln, conf.HTTP.TLS.CertificatePath, conf.HTTP.TLS.PrivateKeyPath)
					}

					log.For(ctx).Info("Starting HTTP server", zap.Stringer("address", ln.Addr()))
					return server.Serve(ln)
				},
				func(e error) {
					log.For(ctx).Info("Shutting HTTP server down")

					shutdownCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
					defer cancel()
					if err := server.Shutdown(shutdownCtx); err != nil {
						log.For(ctx).Fatal("Server Shutdown Failed", zap.Error(err))
					}
				},
			)
		},
	})
	log.CheckErrCtx(ctx, "Unable to run application", err)
}