Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶
func Clear()
Clear can be used to clear all registered handlers. Basically this is only used for testing purposes.
func Register ¶
func Register[Event WebhookEvent, Params any, Handler WebhookHandler[Params]](name string, path string, h Handler, convertFn ParamsConversion[Event, Params])
Register registers a webhook handler by a given webhook event type. The conversion function transform the content of the webhook event into parameters for the handler and is called before the handler invocation. The name is only used for logging purposes and does not need to be identical with any contents from the application config.
Types ¶
type ParamsConversion ¶
type ParamsConversion[Event WebhookEvent, Params any] func(event Event) (Params, error)
ParamsConversion is a function that transforms a webhook event into parameters for a handler. It can also contain some filter logic to skip the handler before calling it. For this a handleerrors.SkipErr can be returned.
type WebhookEvent ¶
type WebhookEvent interface {
githubEvents | gitlabEvents
}
WebhookEvent describes an incoming event from a webhook.
type WebhookHandler ¶
type WebhookHandler[Params any] interface { Handle(ctx context.Context, log *slog.Logger, params Params) error }
WebhookHandler is implemented by a handler to run a specific action. It receives some arbitrary params, which are not specific to a certain webhook event. This way you can run the same handler with different webhook events if desired. Handlers can return a handlerrors.SkipErr error to indicate they did not need to run.