Documentation
¶
Index ¶
- func ChainHandlers(base http.Handler, wrappers ...Middleware) http.Handler
- func GetOranReqErrFunc() func(w http.ResponseWriter, r *http.Request, err error)
- func GetOranRespErrFunc() func(w http.ResponseWriter, r *http.Request, err error)
- type FilterAdapter
- type FilterResponseInterceptor
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainHandlers ¶
func ChainHandlers(base http.Handler, wrappers ...Middleware) http.Handler
ChainHandlers applies each middleware in order to the base router.
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
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) (*FilterAdapter, error)
NewFilterAdapter creates a new filter adapter to be passed to a ResponseFilter
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) EvaluateSelector ¶
EvaluateSelector delegates the function of evaluating the set of search selectors to the selector evaluator.
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 ¶
func (i *FilterResponseInterceptor) Flush(r *http.Request) error
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 ¶
func (i *FilterResponseInterceptor) Header() http.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 ¶
func ErrorJsonifier ¶
func ErrorJsonifier() Middleware
ErrorJsonifier return oran json structure instead of the default plain text
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 findFieldByName 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.
func TrailingSlashStripper ¶
func TrailingSlashStripper() Middleware
TrailingSlashStripper allow API calls with trailing "/"