OxL Справочник OxL
РусскийEnglish

data Ctx

The context of a request, available as ctx in impl of a service and propagated into the calls a handler makes.

Example:

oxl✓ проверяется в CI
service Whoami {
  @public rpc me() -> str
}

impl Whoami {
  rpc me() => "{ctx.node.name.len() > 0} {ctx.traceId.len()}"
}

fn main() io, net {
  print("{Whoami.me()!}")
}
Вывод
true 32
pub(api) data Ctx

С версии. 1.0.0-beta

Поля

pub(api) caller: Principal

Who made the call.

pub(api) via: Principal

The service that made the call (from its mTLS certificate); Anonymous for an external caller or an in-process call.

pub(api) deadline: Time

Absolute deadline (wall clock); far in the future when the call has none.

pub(api) traceId: str

The W3C trace id (32 hex digits) of the request: the same in every process the request touches (§15.5).

pub(api) spanId: str

The id (16 hex digits) of the span the code runs in: the rpc handler's own, or the user span being open; empty without a ctx.

pub(api) meta: Map<str, str>

Request metadata (headers) of the call.

pub(api) idempotencyKey: str

The idempotency key of the call (idempotency-key): chosen by the client for one logical call, sagaId#step inside a saga (§11.3, D-5106); empty when there is none.

pub(api) node: NodeId

The node that runs the handler.

pub(api) resumeFrom: u64? = none

@resumable stream rpcs: the number of elements the client already received (the offset to continue from); none on the first call (metadata x-oxl-resume-from, D-3016).

Методы

userId() -> str | AccessDenied
The id of the calling user; AccessDenied when the caller is not a user (ctx.caller.userId(), §13.2).

Определено в: std/core/rpc.oxl:243

См. также