requireOrgID will either panic (in unit tests) or log an error (in production) if the given resource requires an organization ID and the provided ID is nil.
(ctx context.Context, id uuid.UUID, log slog.Logger)
| 387 | // requireOrgID will either panic (in unit tests) or log an error (in production) |
| 388 | // if the given resource requires an organization ID and the provided ID is nil. |
| 389 | func requireOrgID[T Auditable](ctx context.Context, id uuid.UUID, log slog.Logger) uuid.UUID { |
| 390 | if ResourceRequiresOrgID[T]() && id == uuid.Nil { |
| 391 | var tgt T |
| 392 | resourceName := fmt.Sprintf("%T", tgt) |
| 393 | if flag.Lookup("test.v") != nil { |
| 394 | // In unit tests we panic to fail the tests |
| 395 | panic(fmt.Sprintf("missing required organization ID for resource %q", resourceName)) |
| 396 | } |
| 397 | log.Error(ctx, "missing required organization ID for resource in audit log", |
| 398 | slog.F("resource", resourceName), |
| 399 | ) |
| 400 | } |
| 401 | return id |
| 402 | } |
| 403 | |
| 404 | // InitRequestWithCancel returns a commit function with a boolean arg. |
| 405 | // If the arg is false, future calls to commit() will not create an audit log |