handlers

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 9 Imported by: 0

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.

func Run

func Run[Event WebhookEvent](log *slog.Logger, path string, e Event)

Run triggers all registered handlers asynchronously for the given webhook event type.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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