Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CorsHandler ¶ added in v0.19.0
type CorsHandler interface {
// Cors returns the CORS options that should be applied to the HTTP server.
// These options control how cross-origin requests are handled.
Cors() cors.Options
}
CorsHandler defines the contract for CORS plugins used in the HTTP service layer. Implementations of this interface are responsible for providing CORS configuration that will be applied to the HTTP server.
This enables the HTTP service to support Cross-Origin Resource Sharing (CORS) in a modular and configurable way, allowing for dynamic control over origin, method, and header access policies.
type HTTPAuthenticator ¶ added in v0.19.0
type HTTPAuthenticator interface {
Handler(w http.ResponseWriter, r *http.Request)
}
HTTPAuthenticator defines the contract for authentication plugins used in the HTTP service layer. Implementations of this interface are responsible for registering authentication-related handlers (such as middleware or endpoint-specific logic) into the HTTP service's handler chain.
This allows the HTTP service to integrate authentication behavior (e.g., token validation, identity extraction, etc.) in a pluggable and modular way.
type HTTPSpecAuthenticator ¶ added in v0.19.0
type HTTPSpecAuthenticator interface {
// AuthHandlers returns a function that injects authentication-related handlers
// into the HTTP service, along with any initialization error.
AuthHandlers() (func(ctx context.Context, handlers map[string]interface{}) error, error)
}
HTTPSpecAuthenticator defines the contract for authentication plugins used in the HTTPSpec service layer - http-spec type of services. Implementations of this interface are responsible for registering authentication-related handlers (such as middleware or endpoint-specific logic) into the HTTP service's handler chain.
This allows the HTTP service to integrate authentication behavior (e.g., token validation, identity extraction, etc.) in a pluggable and modular way.
type HTTPSpecRecovery ¶ added in v0.19.0
type HTTPSpecRecovery interface {
// Recover is invoked when a panic occurs during request processing.
// It receives the current request context and is expected to handle
// recovery logic.
Recover(ctx context.Context)
}
HTTPSpecRecovery defines the contract for panic recovery plugins used in the HTTP service layer. Implementations of this interface are responsible for handling unexpected panics during HTTP request processing, allowing the service to recover gracefully and avoid crashes.
This enables the HTTP service to encapsulate panic recovery behavior in a modular way, supporting custom recovery strategies such as logging, metrics, or fallback responses.
type LoggerExtractor ¶
type LoggerExtractor interface {
// Extract retrieves logging attributes from the given context.
// These attributes will be included in structured log messages.
Extract(ctx context.Context) []logger.Attribute
}
LoggerExtractor defines the contract for plugins that enrich log messages by extracting contextual information from a service execution context.
This interface is used across all service types supported by mikros. Implementations are responsible for retrieving relevant attributes from the provided context and returning them as structured log fields.
The extracted attributes will be automatically included in log messages generated during request or task processing, enabling enhanced observability and traceability across service types.
type Tracer ¶
type Tracer interface {
// StartMeasurements initializes tracing or metric collection using the given context.
// It is called at the beginning of a request or task execution, and may extract and record
// service-specific metadata. The returned value will be passed unchanged to ComputeMetrics.
StartMeasurements(ctx context.Context, serviceName string) (interface{}, error)
// ComputeMetrics finalizes the metric computation using the updated context and the
// data returned by StartMeasurements. This method is typically called at the end of
// a request or execution and is responsible for emitting traces, recording durations,
// or reporting collected metrics.
ComputeMetrics(ctx context.Context, serviceName string, data interface{}) error
}
Tracer defines the contract for plugins that enable tracing and performance measurement across all service types supported by mikros.
Implementations of this interface are responsible for collecting runtime metrics and diagnostic data throughout the lifecycle of a service request or execution unit. This enables detailed observability, latency tracking, and performance analysis in a modular and extensible way.
Example:
func (t *MyTracer) StartMeasurements(ctx context.Context, serviceName string) (interface{}, error) {
start := time.Now()
return start, nil
}
func (t *MyTracer) ComputeMetrics(ctx context.Context, serviceName string, data interface{}) error {
startTime, ok := data.(time.Time)
if !ok {
return errors.New("invalid metric data")
}
duration := time.Since(startTime)
log.Printf("[%s] request took %s", serviceName, duration)
return nil
}
type Tracker ¶
type Tracker interface {
// Generate creates a new unique tracker ID to identify a request or task
// execution.
Generate() string
// Add inserts the given tracker ID into the provided context and returns
// the updated context.
Add(ctx context.Context, id string) context.Context
// Retrieve attempts to extract the tracker ID from the given context.
// Returns the ID and a boolean indicating whether it was found.
Retrieve(ctx context.Context) (string, bool)
}
Tracker defines the contract for plugins that manage request tracking across service boundaries in mikros-based systems.
This interface is used to generate and propagate a unique tracking ID for each service call or task execution. The tracker ID enables correlation of logs, traces, and metrics across multiple services, making it easier to follow a request's journey through the system.
Typical implementations may store the ID in the context, headers, or metadata depending on the transport layer.
Example:
func (t *MyTracker) Generate() string {
return uuid.New().String()
}
func (t *MyTracker) Add(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, trackerKey, id)
}
func (t *MyTracker) Retrieve(ctx context.Context) (string, bool) {
val, ok := ctx.Value(trackerKey).(string)
return val, ok
}