// Run starts an http server using the provided config struct. // // This method configures the process to listen for termination signals (SIGINT // and SIGTERM) to trigger a graceful shutdown by way of the graceful package // (https://github.com/tylerb/graceful). func Run(conf Config) { srv := setup(conf) http2.ConfigureServer(srv.Server, nil) if conf.OnStarting != nil { conf.OnStarting() } var err error if conf.TLSCert != "" { err = srv.ListenAndServeTLS(conf.TLSCert, conf.TLSKey) } else { err = srv.ListenAndServe() } if err != nil { log.Error(errors.Wrap(err, "failed to start server")) os.Exit(1) } if conf.OnStopped != nil { conf.OnStopped() } os.Exit(0) }
func run(cmd *cobra.Command, args []string) { var ( cfg Config cfgPath = cmd.PersistentFlags().Lookup("conf").Value.String() ) log.SetLevel(log.InfoLevel) err := config.Read(cfgPath, &cfg) if err != nil { switch cause := errors.Cause(err).(type) { case *config.InvalidConfigError: log.Error("config file: ", cause) default: log.Error(err) } os.Exit(1) } driver, err := initDriver(cfg) if err != nil { log.Error(err) os.Exit(1) } mux := initMux(driver) addr := fmt.Sprintf("0.0.0.0:%d", cfg.Port) http.Run(http.Config{ ListenAddr: addr, Handler: mux, OnStarting: func() { log.Infof("starting federation server - %s", app.Version()) log.Infof("listening on %s", addr) }, }) }
func (h *Handler) writeError(w http.ResponseWriter, err error) { log.Error(err) http.Error(w, "An internal error occurred", http.StatusInternalServerError) }