Skip to main content

gatewaymw/gatewaymw.go (package gatewaymw)

Source: sdks/go/gatewaymw/gatewaymw.go. Back to the Go SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Class Info​

Info is the per request state stored in the request context.

Fields:

NameTypeRequiredDescription
RequestIDstringyesInbound X-Request-Id, or a generated one; also set on the response.
TraceparentstringyesW3C traceparent of the request: the inbound trace id with a new span id, or a new trace.
LangstringyesLanguage of the error messages, fr when Accept-Language starts with fr, en otherwise.
Headershttp.HeaderyesInbound headers of ForwardedHeaders (credentials, tenancy, language) copied onto every Control Plane call.
Decision*eai.PolicyDecisionnoPolicyDecision is the decision part of the Policy Contract v1.
Reservation*eai.ReservationnoReservation is a quota reservation from POST /v1/quotas/reserve. Commit the real usage or Release it; defer r.Close(ctx) releases it when neither happened. Commit and Release reuse the call options given to Reserve (forwarded credentials, trace) with a new Idempotency-Key.

Info.CallOptions​

CallOptions() []eai.CallOption

CallOptions returns the options that make an SDK call on behalf of the caller (credentials, tenancy, trace, request id).

This element takes no parameter.

Returns: []eai.CallOption. A CallOption: CallOption customizes one call.

Model Config​

Config configures the middleware.

Fields:

NameTypeRequiredDescription
Client*eai.ClientnoClient is used for policy and quota calls. Required unless both Action and Reserve are nil.
Actionfunc(r *http.Request) stringyesAction returns the policy action of a request (for example "model.invoke"); nil disables the policy check.
Resourcefunc(r *http.Request) map[string]anyyesResource returns the policy resource ({"type": "model", "id": "..."}); defaults to the request path.
Contextfunc(r *http.Request) map[string]anyyesContext returns the policy context (data_classification, region, purpose...).
Reservefunc(r *http.Request) map[string]anyyesReserve returns the quota reservation request, or nil to skip the reservation for this request.
AllowAnonymousboolyesAllowAnonymous disables the credential check (health endpoints).

Functions​

FromContext​

FromContext(ctx context.Context) *Info

FromContext returns the Info of the current request, or nil.

NameTypeDefaultRequiredDescription
ctxcontext.ContextyesContext of the call: cancellation and deadline.

Returns: *Info. A Info: Info is the per request state stored in the request context.

New​

New(cfg Config) func(http.Handler) http.Handler

New returns the middleware.

NameTypeDefaultRequiredDescription
cfgConfigyesSettings of the middleware: client, policy action, resource, context and quota reservation.

Returns: func(http.Handler) http.Handler. A net/http middleware that wraps the next http.Handler with the credential, policy and quota checks.

WriteError​

WriteError(w http.ResponseWriter, status int, code string, message string, details map[string]any, requestID string)

WriteError writes the platform error envelope.

NameTypeDefaultRequiredDescription
whttp.ResponseWriteryesResponse writer the JSON envelope is written to.
statusintyesHTTP status of the response.
codestringyesMachine code of the error, for example policy_denied; it selects the en and fr messages of message_i18n.
messagestringyesMessage of the envelope, also used in message_i18n when the catalog has no text for the code.
detailsmap[string]anyyesThe details object of the envelope; nil writes an empty object.
requestIDstringyesRequest identifier written as request_id.