Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NoOpCallback ¶
func NoOpErrorHandler ¶
Types ¶
type Config ¶
type Config struct { Enabled bool Config map[EventType][]WebhookConfig `validate:"required_if=Enabled True"` }
Config is a helper struct to define the webhook config in a configuration file
type MockWebhookClient ¶
MockWebhookClient is an autogenerated mock type for the WebhookClient type
func NewMockWebhookClient ¶
func NewMockWebhookClient(t interface { mock.TestingT Cleanup(func()) }) *MockWebhookClient
NewMockWebhookClient creates a new instance of MockWebhookClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockWebhookClient) GetName ¶
func (_m *MockWebhookClient) GetName() string
GetName provides a mock function with given fields:
func (*MockWebhookClient) GetUseDataFrom ¶
func (_m *MockWebhookClient) GetUseDataFrom() string
GetUseDataFrom provides a mock function with given fields:
func (*MockWebhookClient) IsAsync ¶
func (_m *MockWebhookClient) IsAsync() bool
IsAsync provides a mock function with given fields:
func (*MockWebhookClient) IsFinalResponse ¶
func (_m *MockWebhookClient) IsFinalResponse() bool
IsFinalResponse provides a mock function with given fields:
type MockWebhookManager ¶
MockWebhookManager is an autogenerated mock type for the WebhookManager type
func NewMockWebhookManager ¶
func NewMockWebhookManager(t interface { mock.TestingT Cleanup(func()) }) *MockWebhookManager
NewMockWebhookManager creates a new instance of MockWebhookManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockWebhookManager) InvokeWebhooks ¶
func (_m *MockWebhookManager) InvokeWebhooks(_a0 context.Context, _a1 EventType, _a2 interface{}, _a3 func([]byte) error, _a4 func(error) error) error
InvokeWebhooks provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4
func (*MockWebhookManager) IsEventConfigured ¶ added in v1.13.2
func (_m *MockWebhookManager) IsEventConfigured(_a0 EventType) bool
IsEventConfigured provides a mock function with given fields: _a0
type ServiceType ¶
type ServiceType string
type SimpleWebhookManager ¶
type SimpleWebhookManager struct { SyncClients map[EventType][]WebhookClient AsyncClients map[EventType][]WebhookClient }
func (*SimpleWebhookManager) InvokeWebhooks ¶
func (w *SimpleWebhookManager) InvokeWebhooks( ctx context.Context, event EventType, p interface{}, onSuccess func([]byte) error, onError func(error) error, ) error
InvokeWebhooks iterates through the webhooks for a given event and invokes them. Sync webhooks are called first, and only after all of them succeed, the async webhooks are called. Sync webhooks are called in the order that they are defined. The call order of async webhooks are is not guaranteed. If any of the sync clients are set to abort, the whole chain aborts as long as 1 sync request returns error. onSuccess and onError are callbacks that are called after all webhooks are invoked. For sync clients, the payload can be either the original input payload, or the response from another sync webhook. This can be specified in the UseDataFrom field For async clients, the payload is only the original input payload. Only one webhook's response can be used as the finalResponse
func (*SimpleWebhookManager) IsEventConfigured ¶
func (w *SimpleWebhookManager) IsEventConfigured(event EventType) bool
IsEventConfigured checks if the event is configured in the webhook manager Use this method before calling InvokeWebhooks if it is optional to set webhooks for an event
type WebhookClient ¶
type WebhookConfig ¶
type WebhookConfig struct { Name string `yaml:"name" validate:"required"` URL string `yaml:"url" validate:"required,url"` Method string `yaml:"method"` AuthEnabled bool `yaml:"authEnabled"` AuthToken string `yaml:"authToken" validate:"required_if=AuthEnabled True"` Async bool `yaml:"async"` NumRetries int `yaml:"numRetries"` Timeout *int `yaml:"timeout"` // UseDataFrom is the name of the webhook whose response will be used as input to this webhook UseDataFrom string `yaml:"useDataFrom"` // FinalResponse can be set to use the response from this webhook to the onSuccess callback function FinalResponse bool `yaml:"finalResponse"` }
WebhookConfig struct is the configuration for each webhook to be called
type WebhookError ¶ added in v1.13.2
type WebhookError struct {
// contains filtered or unexported fields
}
func NewWebhookError ¶ added in v1.13.2
func NewWebhookError(err error) *WebhookError
func (*WebhookError) Error ¶ added in v1.13.2
func (e *WebhookError) Error() string
Implement errors.Error method
func (*WebhookError) Is ¶ added in v1.13.2
func (e *WebhookError) Is(target error) bool
func (*WebhookError) Unwrap ¶ added in v1.13.2
func (e *WebhookError) Unwrap() error
type WebhookManager ¶
type WebhookManager interface { InvokeWebhooks( context.Context, EventType, interface{}, func(payload []byte) error, func(error) error, ) error IsEventConfigured(EventType) bool }
func InitializeWebhooks ¶
func InitializeWebhooks(cfg *Config, eventList []EventType) (WebhookManager, error)
InitializeWebhooks is a helper method to initialize a webhook manager based on the eventList provided. It returns an error if the configuration is invalid
type WebhookType ¶
type WebhookType string
const ( Async WebhookType = "async" Sync WebhookType = "sync" )