Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var StartCmd = &cobra.Command{ Use: "start", Short: "Start up the Pharos API service", Long: `Start up the Pharos API service Usage pharos start `, RunE: func(cmd *cobra.Command, args []string) (err error) { ctx, signalStop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) defer signalStop() log, err := env.MakeLogger() if err != nil { return err } fileLimit, err := setFileLimit() if err != nil { return err } log.Info("Set file limit", zap.Uint64("fileLimit", fileLimit)) conf, err := env.LoadConfig(ctx) if err != nil { return err } router := setupRouter(conf.DebugHTTP, log) router.GET("/ping", func(c *gin.Context) { c.String(http.StatusOK, "pong") }) s := &http.Server{ Addr: net.JoinHostPort(host, httpPort), Handler: router, } go func() { if err := s.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { log.Error("Http server errored", zap.Error(err)) } }() tcp := transport.NewTCP(transport.Options{ Host: host, Port: port, Reuseport: true, Store: storage.NewInmemoryStore(), Log: log.Named("transport"), }) if err := tcp.Start(ctx); err != nil { return err } log.Info("Listening", zap.Any("config", conf), zap.String("host", host), zap.Int("port", port), zap.String("httpPort", httpPort)) <-ctx.Done() signalStop() log.Info("Shutting down gracefully, press Ctrl+C again to force") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() s.SetKeepAlivesEnabled(false) if err := s.Shutdown(ctx); err != nil { log.Error("Http server forced to shutdown", zap.Error(err)) } if err := tcp.Close(); err != nil { log.Error("TCP server forced to shutdown", zap.Error(err)) } log.Info("Exiting") return nil }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.