api

package
v0.0.0-...-4c823ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOranReqErrFunc

func GetOranReqErrFunc() func(w http.ResponseWriter, r *http.Request, err error)

GetOranReqErrFunc override default validation errors to allow for O-RAN specific struct

func GetOranRespErrFunc

func GetOranRespErrFunc() func(w http.ResponseWriter, r *http.Request, err error)

GetOranRespErrFunc override default internal server error to allow for O-RAN specific struct

func GracefulShutdown

func GracefulShutdown(srv *http.Server) error

GracefulShutdown allow graceful shutdown with timeout

func NotFoundFunc

func NotFoundFunc() func(w http.ResponseWriter, r *http.Request)

NotFoundFunc is used to override the default 404 response which is a text only reply so that we can respond with the required JSON body.

func ValidateCallbackURL

func ValidateCallbackURL(callback string) error

ValidateCallbackURL ensures that the URL used in subscription callback meets our requirements

Types

type FilterAdapter

type FilterAdapter struct {
	// contains filtered or unexported fields
}

FilterAdapter is an abstraction that wraps the search projector/selector functionality so that these objects can be created once at server initialization time and re-used in the ResponseFilter middleware.

func NewFilterAdapter

func NewFilterAdapter(logger *slog.Logger, swagger *openapi3.T) (*FilterAdapter, error)

NewFilterAdapter creates a new filter adapter to be passed to a ResponseFilter

func (*FilterAdapter) EnforceRequiredFields

func (a *FilterAdapter) EnforceRequiredFields(projector *search.Projector, r *http.Request) error

EnforceRequiredFields ensures that required fields are always included and never excluded

func (*FilterAdapter) Error

func (a *FilterAdapter) Error(w http.ResponseWriter, details string, status int) error

Error sends an error using the proper ORAN format

func (*FilterAdapter) EvaluateProjector

func (a *FilterAdapter) EvaluateProjector(projector *search.Projector,
	object any) (map[string]any, error)

EvaluateProjector delegates the function of evaluating the set of field projections to the projector evaluator.

func (*FilterAdapter) EvaluateSelector

func (a *FilterAdapter) EvaluateSelector(selector *search.Selector, object any) (bool, error)

EvaluateSelector delegates the function of evaluating the set of search selectors to the selector evaluator.

func (*FilterAdapter) ParseFields

func (a *FilterAdapter) ParseFields(fields ...string) ([]search.Path, error)

ParseFields delegates the function of parsing the include/exclude fields to the path parser.

func (*FilterAdapter) ParseFilter

func (a *FilterAdapter) ParseFilter(query string) (*search.Selector, error)

ParseFilter delegates the function of parsing the filter fields to the selector parser.

type FilterResponseInterceptor

type FilterResponseInterceptor struct {
	// contains filtered or unexported fields
}

FilterResponseInterceptor implements the http.ResponseWriter interface so that it can be used to intercept all operations intended for the request's ResponseWriter into a local buffer. At the end of the request the local buffer is evaluated against the selector/projector built from the 'fields', 'exclude_fields', and 'filter' query parameters and transforms the response object accordingly.

func (*FilterResponseInterceptor) Flush

Flush is invoked at the end of the request so that the response can be transformed/filtered if necessary. Both the selector (filtering) and projector (transformations) are applied to any operations that have a 200 status code and contain valid JSON for either a list or object representation.

func (*FilterResponseInterceptor) Header

Header is a simple pass-through to the original http.ResponseWriter's Header method

func (*FilterResponseInterceptor) Write

func (i *FilterResponseInterceptor) Write(data []byte) (int, error)

Write intercepts the bytes intended for the underlying http.ResponseWriter and stores them locally for later processing.

func (*FilterResponseInterceptor) WriteHeader

func (i *FilterResponseInterceptor) WriteHeader(statusCode int)

WriteHeader intercepts the response's status code and stores it locally. It is not passed through in case processing in this interceptor fails, and we need to override the response code.

type Middleware

type Middleware = func(http.Handler) http.Handler

func LogDuration

func LogDuration() Middleware

LogDuration log time taken to complete a request. TODO: This is just get started with middleware but should be replaced with something that's more suitable for production i.e OpenTelemetry https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/examples/prometheus/main.go

func OpenAPIValidation

func OpenAPIValidation(swagger *openapi3.T) Middleware

OpenAPIValidation to validate all incoming requests as specified in the spec

func ResponseFilter

func ResponseFilter(adapter *FilterAdapter) Middleware

ResponseFilter intercepts the response body and removes fields that are not required.

Directories

Path Synopsis
Package generated provides primitives to interact with the openapi HTTP API.
Package generated provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL