api

package
v0.0.0-...-91f48cd Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentDuration

func InstrumentDuration(handlerName string) func(http.Handler) http.Handler

InstrumentDuration wraps a handler with request duration metrics

func InstrumentInflight

func InstrumentInflight(handler http.Handler) http.Handler

InstrumentInflight wraps a handler with inflight request metrics

func InstrumentResponseSize

func InstrumentResponseSize(handlerName string) func(http.Handler) http.Handler

InstrumentResponseSize wraps a handler with response size metrics

func ReturnESJSON

func ReturnESJSON(w http.ResponseWriter, code int, data any)

ReturnESJSON is a custom response helper that preserves the storage backend URL formatting. This is needed because OpenSearch requires literal & characters in URLs, but Go's JSON marshaler escapes them as \u0026.

Example:

events := []Event{...}
ReturnESJSON(w, http.StatusOK, map[string]any{
	"events": events,
	"total":  len(events),
})

func Server

func Server(validator gopherpolicy.Validator, storageInterface storage.Storage) error

Server Set up and start the API server using httpapi patterns

Types

type EventList

type EventList struct {
	NextURL string              `json:"next,omitempty"`
	PrevURL string              `json:"previous,omitempty"`
	Events  []*hermes.ListEvent `json:"events"`
	Total   int                 `json:"total"`
}

EventList is the model for JSON returned by the ListEvents API call

type MetricsAPI

type MetricsAPI struct{}

MetricsAPI handles Prometheus metrics

func NewMetricsAPI

func NewMetricsAPI() *MetricsAPI

NewMetricsAPI creates a metrics API instance

func (*MetricsAPI) AddTo

func (api *MetricsAPI) AddTo(r *mux.Router)

AddTo implements httpapi.API interface

type V1API

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

V1API implements the v1 API endpoints using httpapi patterns

func NewV1API

func NewV1API(validator gopherpolicy.Validator, storageInterface storage.Storage) *V1API

NewV1API creates a new V1API instance with the provided validator and storage.

Example:

validator := gopherpolicy.NewValidator(enforcer, logger)
storage := opensearch.NewStorage(config)
api := NewV1API(validator, storage)

func (*V1API) AddTo

func (api *V1API) AddTo(r *mux.Router)

AddTo implements httpapi.API interface

func (*V1API) VersionData

func (api *V1API) VersionData() VersionData

VersionData returns the version data for this API

type VersionAPI

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

VersionAPI handles version advertisement

func NewVersionAPI

func NewVersionAPI(v1VersionData VersionData) *VersionAPI

NewVersionAPI creates a version API instance

func (*VersionAPI) AddTo

func (api *VersionAPI) AddTo(r *mux.Router)

AddTo implements httpapi.API interface

type VersionData

type VersionData struct {
	Status string            `json:"status"`
	ID     string            `json:"id"`
	Links  []versionLinkData `json:"links"`
}

VersionData is used by version advertisement handlers.

Jump to

Keyboard shortcuts

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