startServices Handles the start process of services for the current application. Iterates over all configured services and tries to start them, returning an error if any error occurs.
(ctx context.Context)
| 79 | // startServices Handles the start process of services for the current application. |
| 80 | // Iterates over all configured services and tries to start them, returning an error if any error occurs. |
| 81 | func (app *App) startServices(ctx context.Context) error { |
| 82 | if !app.hasConfiguredServices() { |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | var errs []error |
| 87 | for idx, srv := range app.configured.Services { |
| 88 | if srv == nil { |
| 89 | return fmt.Errorf("fiber: service at index %d is nil", idx) |
| 90 | } |
| 91 | if err := ctx.Err(); err != nil { |
| 92 | // Context is canceled, return an error the soonest possible, so that |
| 93 | // the user can see the context cancellation error and act on it. |
| 94 | return fmt.Errorf("context canceled while starting service %s: %w", srv.String(), err) |
| 95 | } |
| 96 | |
| 97 | err := srv.Start(ctx) |
| 98 | if err == nil { |
| 99 | // mark the service as started |
| 100 | app.state.setService(srv) |
| 101 | continue |
| 102 | } |
| 103 | |
| 104 | if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { |
| 105 | return fmt.Errorf("service %s start: %w", srv.String(), err) |
| 106 | } |
| 107 | |
| 108 | errs = append(errs, fmt.Errorf("service %s start: %w", srv.String(), err)) |
| 109 | } |
| 110 | return errors.Join(errs...) |
| 111 | } |
| 112 | |
| 113 | // shutdownServices Handles the shutdown process of services for the current application. |
| 114 | // Iterates over all the started services in reverse order and tries to terminate them, |