Documentation
¶
Index ¶
- Constants
- func JSON(w http.ResponseWriter, code int, v any, pretty bool)
- func Pack2[K any, V any](seq iter.Seq2[K, V], sliceSizes []int) iter.Seq2[[]K, []V]
- type BatchDataRequestV1
- type BatchDataRequestV1Unparsed
- type BatchDataRespType
- type BatchDataResponseV1
- type BatchQueryHandler
- type DataResponseWithHTTPCodeV1
- type ErrorResponseWithHTTPCodeV1
Constants ¶
const MsgInputsKeyMissing = "'inputs' key missing from the request"
const (
PrometheusHandle = "v1/batch/data"
)
Variables ¶
This section is empty.
Functions ¶
func JSON ¶ added in v1.46.0
func JSON(w http.ResponseWriter, code int, v any, pretty bool)
Adapted from upstream OPA: v1/server/writer/writer.go JSON writes a response with the specified status code and object. The object will be JSON serialized.
Note(philip): If JSON encoding the payload fails, we may end up with an incorrect status code for the error payload. This happens because we cannot update the status code header after setting it; that header is sent over first, before the payload.
This is a conscious tradeoff for the Batch Query use case because it allows us to avoid buffering a potentially massive JSON response in memory multiple times before sending it. The current design pays the buffering cost just once, in the json.Encoder, versus twice or more in other approaches, like using json.Marshal (which copies its buffer contents to a new byte slice before returning), or using a bytes.Buffer as the io.Writer target for the json.Encoder.
Types ¶
type BatchDataRequestV1 ¶
type BatchDataRequestV1 struct {
Inputs map[string]*any `json:"inputs"`
CommonInput *any `json:"common_input,omitempty"`
}
BatchDataRequestV1 models the request message for batched Data API POST operations. CommonInput is intended as an optional field, which is merged with each query's input object before evaluation.
type BatchDataRequestV1Unparsed ¶
type BatchDataRequestV1Unparsed struct {
Inputs map[string]*json.RawMessage `json:"inputs"` // Parsing of the inputs is deferred.
CommonInput *any `json:"common_input,omitempty"`
}
type BatchDataRespType ¶
type BatchDataRespType interface {
GetHTTPStatusCode() string
}
Note(philip): This is a bit of a hack to ensure we only get the 2x intended types embedded in the BatchDataResponse struct.
type BatchDataResponseV1 ¶
type BatchDataResponseV1 struct {
Metrics types.MetricsV1 `json:"metrics,omitempty"`
Responses map[string]BatchDataRespType `json:"responses,omitempty"`
Warning *types.Warning `json:"warning,omitempty"`
BatchDecisionID string `json:"batch_decision_id,omitempty"`
}
BatchDataResponseV1 models the response message for batched Data API read operations.
func (*BatchDataResponseV1) UnmarshalJSON ¶
func (bdr *BatchDataResponseV1) UnmarshalJSON(b []byte) error
Note(philip): We have to do custom JSON unmarshalling here to work around the fact that our response representation is not perfect.
type BatchQueryHandler ¶
type BatchQueryHandler interface {
http.Handler
GetManager() *plugins.Manager
SetManager(*plugins.Manager) error
WithLicensedMode(bool) BatchQueryHandler
WithDecisionIDFactory(func() string) BatchQueryHandler
WithDecisionLogger(logger func(context.Context, *server.Info) error) BatchQueryHandler
}
func Handler ¶
func Handler(l logging.Logger) BatchQueryHandler
type DataResponseWithHTTPCodeV1 ¶
type DataResponseWithHTTPCodeV1 struct {
types.DataResponseV1
HTTPStatusCode string `json:"http_status_code,omitempty"`
}
DataResponseWithCodeV1 models the response message for Data API read operations.
func (DataResponseWithHTTPCodeV1) GetHTTPStatusCode ¶
func (r DataResponseWithHTTPCodeV1) GetHTTPStatusCode() string
type ErrorResponseWithHTTPCodeV1 ¶
type ErrorResponseWithHTTPCodeV1 struct {
DecisionID string `json:"decision_id,omitempty"`
HTTPStatusCode string `json:"http_status_code,omitempty"`
types.ErrorV1
}
func (ErrorResponseWithHTTPCodeV1) GetHTTPStatusCode ¶
func (r ErrorResponseWithHTTPCodeV1) GetHTTPStatusCode() string