Documentation
¶
Overview ¶
Package faults provides common headers and client-side fault injection functionality.
Index ¶
Constants ¶
const ( FaultServerAddressHeader = "x-bp-fault-server-address" FaultServerMethodHeader = "x-bp-fault-server-method" FaultDelayMsHeader = "x-bp-fault-delay-ms" FaultDelayPercentageHeader = "x-bp-fault-delay-percentage" FaultAbortCodeHeader = "x-bp-fault-abort-code" FaultAbortMessageHeader = "x-bp-fault-abort-message" FaultAbortPercentageHeader = "x-bp-fault-abort-percentage" )
Variables ¶
This section is empty.
Functions ¶
func WithDefaultAbort ¶
WithDefaultAbort is an option to set the default abort function for the Injector.
Types ¶
type Abort ¶
Abort is the function type to inject a protocol-specific fault with the given code and message.
type Headers ¶
type Headers interface {
// Lookup returns the value of a protocol-specific header with the
// given key.
Lookup(ctx context.Context, key string) (string, error)
}
Headers is an interface to be implemented by the caller to allow protocol-specific header lookup. Using an interface here rather than a function type avoids any potential closure requirements of a function.
type Injector ¶
type Injector[T any] struct { // contains filtered or unexported fields }
Injector contains the data common across all requests needed to inject faults on outgoing requests.
func NewInjector ¶
func NewInjector[T any](clientName, callerName string, abortCodeMin, abortCodeMax int, option ...func(*Injector[T])) *Injector[T]
NewInjector creates a new Injector with the provided parameters.
func (*Injector[T]) Inject ¶
func (i *Injector[T]) Inject(ctx context.Context, address, method string, headers Headers, resume Resume[T]) (T, error)
Inject injects a fault using the Injector default fault function on the outgoing request if it matches the header configuration.
func (*Injector[T]) InjectWithAbortOverride ¶
func (i *Injector[T]) InjectWithAbortOverride(ctx context.Context, address, method string, headers Headers, resume Resume[T], abort Abort[T]) (T, error)
InjectWithAbortOverride injects a fault using the provided fault function on the outgoing request if it matches the header configuration.