File size: 1,626 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
package app
import (
"context"
"log/slog"
"net/http"
"os"
"github.com/pkg/errors"
)
var triggerSignals []os.Signal
// Run will start the application and start serving traffic.
func (app *App) Run(ctx context.Context) error {
return app.mgr.Run(app.Context(ctx))
}
func (app *App) _Run(ctx context.Context) error {
go func() {
err := app.Engine.Run(ctx)
if err != nil {
app.Logger.ErrorContext(ctx, "Failed to run engine.", slog.Any("error", err))
}
}()
err := app.RiverUI.Start(ctx)
if err != nil {
app.Logger.ErrorContext(ctx, "Failed to start River UI.", slog.Any("error", err))
}
go app.events.Run(ctx)
if app.sysAPISrv != nil {
app.Logger.InfoContext(ctx, "System API server started.",
slog.String("address", app.sysAPIL.Addr().String()))
go func() {
if err := app.sysAPISrv.Serve(app.sysAPIL); err != nil {
app.Logger.ErrorContext(ctx, "Failed to serve system API.", slog.Any("error", err))
}
}()
}
if app.smtpsrv != nil {
app.Logger.InfoContext(ctx, "SMTP server started.",
slog.String("address", app.smtpsrvL.Addr().String()))
go func() {
if err := app.smtpsrv.ServeSMTP(app.smtpsrvL); err != nil {
app.Logger.ErrorContext(ctx, "Failed to serve SMTP.", slog.Any("error", err))
}
}()
}
app.Logger.InfoContext(ctx, "Listening.",
slog.String("address", app.l.Addr().String()),
slog.String("url", app.ConfigStore.Config().PublicURL()),
)
err = app.srv.Serve(app.l)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
return errors.Wrap(err, "serve HTTP")
}
if app.hSrv != nil {
app.hSrv.Resume()
}
<-ctx.Done()
return nil
}
|