gatewaymw/gatewaymw.go (package gatewaymw)
Source: sdks/go/gatewaymw/gatewaymw.go. Back to the Go SDK reference index.
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:
| Name | Type | Required | Description |
|---|---|---|---|
RequestID | string | yes | Inbound X-Request-Id, or a generated one; also set on the response. |
Traceparent | string | yes | W3C traceparent of the request: the inbound trace id with a new span id, or a new trace. |
Lang | string | yes | Language of the error messages, fr when Accept-Language starts with fr, en otherwise. |
Headers | http.Header | yes | Inbound headers of ForwardedHeaders (credentials, tenancy, language) copied onto every Control Plane call. |
Decision | *eai.PolicyDecision | no | PolicyDecision is the decision part of the Policy Contract v1. |
Reservation | *eai.Reservation | no | Reservation 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:
| Name | Type | Required | Description |
|---|---|---|---|
Client | *eai.Client | no | Client is used for policy and quota calls. Required unless both Action and Reserve are nil. |
Action | func(r *http.Request) string | yes | Action returns the policy action of a request (for example "model.invoke"); nil disables the policy check. |
Resource | func(r *http.Request) map[string]any | yes | Resource returns the policy resource ({"type": "model", "id": "..."}); defaults to the request path. |
Context | func(r *http.Request) map[string]any | yes | Context returns the policy context (data_classification, region, purpose...). |
Reserve | func(r *http.Request) map[string]any | yes | Reserve returns the quota reservation request, or nil to skip the reservation for this request. |
AllowAnonymous | bool | yes | AllowAnonymous disables the credential check (health endpoints). |
Functions
FromContext
FromContext(ctx context.Context) *Info
FromContext returns the Info of the current request, or nil.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
ctx | context.Context | yes | Context 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
cfg | Config | yes | Settings 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.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
w | http.ResponseWriter | yes | Response writer the JSON envelope is written to. | |
status | int | yes | HTTP status of the response. | |
code | string | yes | Machine code of the error, for example policy_denied; it selects the en and fr messages of message_i18n. | |
message | string | yes | Message of the envelope, also used in message_i18n when the catalog has no text for the code. | |
details | map[string]any | yes | The details object of the envelope; nil writes an empty object. | |
requestID | string | yes | Request identifier written as request_id. |