notify

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 9 Imported by: 0

README

Common Go notify code shared between my projects

GoDoc Build Coverage

License

This project is subject to the the MIT License. See LICENSE information for details.

Documentation

Overview

Package notify provides a generic interface to send user notifications. The actual transport behind (mail, webhook) can be plugged in as needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteHTMLTemplate

func ExecuteHTMLTemplate(html string, params any) (string, error)

ExecuteHTMLTemplate invokes [htmltemplat.Execute] using the given template text and parameter object.

func ExecuteTextTemplate

func ExecuteTextTemplate(text string, params any) (string, error)

ExecuteTextTemplate invokes [texttemplat.Execute] using the given template text and parameter object.

Types

type LogPayload

type LogPayload struct {
	Logger *slog.Logger
	Level  slog.Level
	Msg    string
}

func (*LogPayload) Send

func (p *LogPayload) Send(ctx context.Context, params any) error

type NamedValue

type NamedValue struct {
	Name  string
	Value any
}

NamedValue represents a named value pair as found in a parameter object.

func DecodeParams

func DecodeParams(params any) ([]NamedValue, error)

DecodeParams decodes a struct object to the contained NamedValue pairs. If the params object is nil, an empty array is returned.

type Payload

type Payload[T any] interface {
	// Send sends the Payload after applying the given params object.
	Send(ctx context.Context, params any) error
}

Payload represents a single notification including content and transport specific attributes.

type PayloadRegistry

type PayloadRegistry[T any] struct {
	// contains filtered or unexported fields
}

PayloadRegistry represents a registry of named Payloads and by this a single location to store and access the notifications of an application.

func (*PayloadRegistry[T]) Add

func (r *PayloadRegistry[T]) Add(name string, payload Payload[T])

Add adds a the given Payload instance using the given name. Multiple payloads can be defined for a single name.

func (*PayloadRegistry[T]) Get

func (r *PayloadRegistry[T]) Get(name string) Payloads[T]

Get gets the Payload instances defined for the given name.

type Payloads

type Payloads[T any] []Payload[T]

Payloads represents an array of Payload instances.

func (Payloads[T]) Send

func (payloads Payloads[T]) Send(ctx context.Context, params any) error

Send invokes Payload.Send for all given Payload instances.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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