webhook

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SourceKey            = "source"
	ContextKey           = "extra"
	ErrorKeys            = []string{"error", "err"}
	RequestKey           = "request"
	RequestIgnoreHeaders = false
)

Functions

func DefaultConverter

func DefaultConverter(addSource bool, replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) map[string]any

Types

type Converter

type Converter func(addSource bool, replaceAttr func(groups []string, a slog.Attr) slog.Attr, loggerAttr []slog.Attr, groups []string, record *slog.Record) map[string]any

type Option

type Option struct {
	// log level (default: debug)
	Level slog.Leveler

	// URL
	Endpoint string
	Timeout  time.Duration // default: 10s

	// optional: customize webhook event builder
	Converter Converter
	// optional: custom marshaler
	Marshaler func(v any) ([]byte, error)
	// optional: fetch attributes from context
	AttrFromContext []func(ctx context.Context) []slog.Attr

	// optional: see slog.HandlerOptions
	AddSource   bool
	ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
}

func (Option) NewWebhookHandler

func (o Option) NewWebhookHandler() slog.Handler

type WebhookHandler

type WebhookHandler struct {
	// contains filtered or unexported fields
}

func (*WebhookHandler) Enabled

func (h *WebhookHandler) Enabled(_ context.Context, level slog.Level) bool

func (*WebhookHandler) Handle

func (h *WebhookHandler) Handle(ctx context.Context, record slog.Record) error

func (*WebhookHandler) WithAttrs

func (h *WebhookHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*WebhookHandler) WithGroup

func (h *WebhookHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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