handler

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthHandler

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

healthHandler handles requests to the /health endpoint.

func NewStdHandler

func NewStdHandler(ctx context.Context, mgr PluginManager, cfg *Config, moduleName string) (http.Handler, error)

NewStdHandler initializes a new processor with plugins and steps.

func RecordHTTPRequest added in v1.4.0

func RecordHTTPRequest(ctx context.Context, statusCode int, action, role, senderID, recipientID string)

func StatusClass added in v1.4.0

func StatusClass(statusCode int) string

StatusClass returns the HTTP status class string (e.g. 200 -> "2xx").

Types

type Config

type Config struct {
	Plugins          PluginCfg `yaml:"plugins"`
	Steps            []string
	Type             Type
	RegistryURL      string `yaml:"registryUrl"`
	Role             model.Role
	SubscriberID     string           `yaml:"subscriberId"`
	HttpClientConfig HttpClientConfig `yaml:"httpClientConfig"`
	// BasePath is the HTTP path prefix at which this module is mounted (e.g.
	// "/bap/receiver/"). Set by the module layer from module.Config.Path; not
	// read from YAML. Steps use it to strip the prefix before calling plugins.
	BasePath string `yaml:"-"`
}

Config holds the configuration for request processing handlers.

type HTTPMetrics added in v1.4.0

type HTTPMetrics struct {
	HttpRequestCount metric.Int64Counter
}

func GetHTTPMetrics added in v1.4.0

func GetHTTPMetrics(_ context.Context) (*HTTPMetrics, error)

GetHTTPMetrics returns HTTPMetrics bound to the current global MeterProvider, rebuilding only when the provider has been replaced since the last call.

type HandlerMetrics added in v1.3.0

type HandlerMetrics struct {
	SignatureValidationsTotal metric.Int64Counter
	SchemaValidationsTotal    metric.Int64Counter
	RoutingDecisionsTotal     metric.Int64Counter
}

HandlerMetrics exposes handler-related metric instruments.

func GetHandlerMetrics added in v1.3.0

func GetHandlerMetrics(_ context.Context) (*HandlerMetrics, error)

GetHandlerMetrics returns HandlerMetrics bound to the current global MeterProvider, rebuilding only when the provider has been replaced since the last call.

type HttpClientConfig

type HttpClientConfig struct {
	// MaxIdleConns controls the maximum number of idle (keep-alive)
	// connections across all hosts.
	MaxIdleConns int `yaml:"maxIdleConns"`

	// IdleConnTimeout is the maximum amount of time an idle
	// (keep-alive) connection will remain idle before closing itself.
	IdleConnTimeout time.Duration `yaml:"idleConnTimeout"`

	// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
	// (keep-alive) connections to keep per-host.
	MaxIdleConnsPerHost int `yaml:"maxIdleConnsPerHost"`

	// ResponseHeaderTimeout, if non-zero, specifies the amount of time to wait
	// for a server's response headers after fully writing the request.
	ResponseHeaderTimeout time.Duration `yaml:"responseHeaderTimeout"`
}

HttpClientConfig defines the configuration for the HTTP transport layer.

type InstrumentedResponseStep added in v1.7.0

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

InstrumentedResponseStep wraps a response processing step with telemetry instrumentation.

func NewInstrumentedResponseStep added in v1.7.0

func NewInstrumentedResponseStep(step ResponseStepRunner, stepName, moduleName string) (*InstrumentedResponseStep, error)

NewInstrumentedResponseStep returns a telemetry-enabled wrapper around a definition.ResponseStep.

func (*InstrumentedResponseStep) RunOnResponse added in v1.7.0

RunOnResponse executes the underlying response step and records RED style metrics.

Note: validateAckSign is a soft-failure step — it returns nil even on signature verification failures (degraded-trust design). onix_step_errors_total will never increment for that step; its own log.Warnf calls are the only signal for soft failures.

type InstrumentedStep added in v1.3.0

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

InstrumentedStep wraps a processing step with telemetry instrumentation.

func NewInstrumentedStep added in v1.3.0

func NewInstrumentedStep(step StepRunner, stepName, moduleName string) (*InstrumentedStep, error)

NewInstrumentedStep returns a telemetry enabled wrapper around a definition.Step.

func (*InstrumentedStep) Run added in v1.3.0

func (is *InstrumentedStep) Run(ctx *model.StepContext) error

Run executes the underlying step and records RED style metrics.

type PluginCfg

type PluginCfg struct {
	SchemaValidator    *plugin.Config  `yaml:"schemaValidator,omitempty"`
	PolicyChecker      *plugin.Config  `yaml:"checkPolicy,omitempty"`
	PayloadTransformer *plugin.Config  `yaml:"payloadTransformer,omitempty"`
	SignValidator      *plugin.Config  `yaml:"signValidator,omitempty"`
	Publisher          *plugin.Config  `yaml:"publisher,omitempty"`
	Signer             *plugin.Config  `yaml:"signer,omitempty"`
	Router             *plugin.Config  `yaml:"router,omitempty"`
	Cache              *plugin.Config  `yaml:"cache,omitempty"`
	Registry           *plugin.Config  `yaml:"registry,omitempty"`
	KeyManager         *plugin.Config  `yaml:"keyManager,omitempty"`
	ManifestLoader     *plugin.Config  `yaml:"manifestLoader,omitempty"`
	TransportWrapper   *plugin.Config  `yaml:"transportWrapper,omitempty"`
	PayloadStore       *plugin.Config  `yaml:"payloadStore,omitempty"`
	Middleware         []plugin.Config `yaml:"middleware,omitempty"`
	Steps              []plugin.Config
}

PluginCfg holds the configuration for various plugins.

func (*PluginCfg) PluginEntries added in v1.6.0

func (p *PluginCfg) PluginEntries() []telemetry.PluginEntry

PluginEntries returns a flat list of all configured plugins in this PluginCfg. Each named slot contributes one entry; Steps and Middleware contribute one entry per item. Update this method whenever a new plugin slot is added to PluginCfg so that the onix_plugin_info gauge stays complete.

type PluginManager

type PluginManager interface {
	Middleware(ctx context.Context, cfg *plugin.Config) (func(http.Handler) http.Handler, error)
	SignValidator(ctx context.Context, cfg *plugin.Config) (definition.SignValidator, error)
	Validator(ctx context.Context, cfg *plugin.Config) (definition.SchemaValidator, error)
	Router(ctx context.Context, cfg *plugin.Config) (definition.Router, error)
	Publisher(ctx context.Context, cfg *plugin.Config) (definition.Publisher, error)
	Signer(ctx context.Context, cfg *plugin.Config) (definition.Signer, error)
	Step(ctx context.Context, cfg *plugin.Config) (definition.Step, error)
	PolicyChecker(ctx context.Context, manifestLoader definition.ManifestLoader, cfg *plugin.Config) (definition.PolicyChecker, error)
	Cache(ctx context.Context, cfg *plugin.Config) (definition.Cache, error)
	Registry(ctx context.Context, cache definition.Cache, cfg *plugin.Config) (definition.RegistryLookup, error)
	KeyManager(ctx context.Context, rLookup definition.RegistryLookup, cfg *plugin.Config) (definition.KeyManager, error)
	ManifestLoader(ctx context.Context, cache definition.Cache, lookup definition.RegistryMetadataLookup, cfg *plugin.Config) (definition.ManifestLoader, error)
	TransportWrapper(ctx context.Context, cfg *plugin.Config) (definition.TransportWrapper, error)
	SchemaValidator(ctx context.Context, cfg *plugin.Config) (definition.SchemaValidator, error)
	PayloadStore(ctx context.Context, cache definition.Cache, namespace string, cfg *plugin.Config) (definition.PayloadStore, error)
}

PluginManager defines an interface for managing plugins dynamically.

type ResponseStepRunner added in v1.7.0

type ResponseStepRunner interface {
	RunOnResponse(*model.StepContext, *model.ResponseStepContext) error
}

ResponseStepRunner is the minimal contract required for response step instrumentation.

type StepMetrics added in v1.3.0

type StepMetrics struct {
	StepExecutionDuration metric.Float64Histogram
	StepExecutionTotal    metric.Int64Counter
	StepErrorsTotal       metric.Int64Counter
}

StepMetrics exposes step execution metric instruments.

func GetStepMetrics added in v1.3.0

func GetStepMetrics(_ context.Context) (*StepMetrics, error)

GetStepMetrics returns StepMetrics bound to the current global MeterProvider, rebuilding only when the provider has been replaced since the last call.

type StepRunner added in v1.3.0

type StepRunner interface {
	Run(*model.StepContext) error
}

StepRunner represents the minimal contract required for step instrumentation.

type Type

type Type string

Type defines different handler types for processing requests.

const (
	// HandlerTypeStd represents the standard handler type used for general request processing.
	HandlerTypeStd Type = "std"
)

Jump to

Keyboard shortcuts

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