notif

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderGotify  = "gotify"
	ProviderNtfy    = "ntfy"
	ProviderWebhook = "webhook"
)

Variables

View Source
var (
	ErrMissingToken     = E.New("token is required")
	ErrURLMissingScheme = E.New("url missing scheme, expect 'http://' or 'https://'")
)
View Source
var (
	ErrMissingNotifProvider     = E.New("missing notification provider")
	ErrInvalidNotifProviderType = E.New("invalid notification provider type")
	ErrUnknownNotifProvider     = E.New("unknown notification provider")
)

Functions

func Notify

func Notify(msg *LogMessage)

Types

type Color

type Color uint
const (
	ColorError   Color = 0xff0000
	ColorSuccess Color = 0x00ff00
	ColorInfo    Color = 0x0000ff
)

func (Color) DecString

func (c Color) DecString() string

func (Color) HexString

func (c Color) HexString() string

func (Color) String

func (c Color) String() string

type Dispatcher

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

func StartNotifDispatcher

func StartNotifDispatcher(parent task.Parent) *Dispatcher

func (*Dispatcher) RegisterProvider

func (disp *Dispatcher) RegisterProvider(cfg *NotificationConfig)

type GotifyClient

type GotifyClient struct {
	ProviderBase
}

func (*GotifyClient) GetURL

func (client *GotifyClient) GetURL() string

func (*GotifyClient) MakeBody

func (client *GotifyClient) MakeBody(logMsg *LogMessage) (io.Reader, error)

MakeBody implements Provider.

type GotifyMessage

type GotifyMessage model.MessageExternal

type LogField

type LogField struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type LogFields

type LogFields []LogField

func (*LogFields) Add

func (f *LogFields) Add(name, value string)

type LogMessage

type LogMessage struct {
	Level  zerolog.Level
	Title  string
	Extras LogFields
	Color  Color
}

type NotificationConfig

type NotificationConfig struct {
	ProviderName string   `json:"provider"`
	Provider     Provider `json:"-"`
}

func (*NotificationConfig) UnmarshalMap

func (cfg *NotificationConfig) UnmarshalMap(m map[string]any) (err E.Error)

UnmarshalMap implements MapUnmarshaler.

type Ntfy

type Ntfy struct {
	ProviderBase
	Topic string    `json:"topic"`
	Style NtfyStyle `json:"style"`
}

See https://docs.ntfy.sh/publish

func (*Ntfy) GetMIMEType

func (n *Ntfy) GetMIMEType() string

func (*Ntfy) GetToken

func (n *Ntfy) GetToken() string

func (*Ntfy) GetURL

func (n *Ntfy) GetURL() string

func (*Ntfy) MakeBody

func (n *Ntfy) MakeBody(logMsg *LogMessage) (io.Reader, error)

func (*Ntfy) SetHeaders

func (n *Ntfy) SetHeaders(logMsg *LogMessage, headers http.Header)

func (*Ntfy) Validate

func (n *Ntfy) Validate() E.Error

type NtfyStyle

type NtfyStyle string
const (
	NtfyStyleMarkdown NtfyStyle = "markdown"
	NtfyStylePlain    NtfyStyle = "plain"
)

type Provider

type Provider interface {
	utils.CustomValidator

	GetName() string
	GetURL() string
	GetToken() string
	GetMethod() string
	GetMIMEType() string

	MakeBody(logMsg *LogMessage) (io.Reader, error)
	SetHeaders(logMsg *LogMessage, headers http.Header)
	// contains filtered or unexported methods
}

type ProviderBase

type ProviderBase struct {
	Name  string `json:"name" validate:"required"`
	URL   string `json:"url" validate:"url"`
	Token string `json:"token"`
}

func (*ProviderBase) GetMIMEType

func (base *ProviderBase) GetMIMEType() string

func (*ProviderBase) GetMethod

func (base *ProviderBase) GetMethod() string

func (*ProviderBase) GetName

func (base *ProviderBase) GetName() string

func (*ProviderBase) GetToken

func (base *ProviderBase) GetToken() string

func (*ProviderBase) GetURL

func (base *ProviderBase) GetURL() string

func (*ProviderBase) SetHeaders

func (base *ProviderBase) SetHeaders(logMsg *LogMessage, headers http.Header)

func (*ProviderBase) Validate

func (base *ProviderBase) Validate() E.Error

Validate implements the utils.CustomValidator interface.

type ProviderConfig

type ProviderConfig map[string]any

type ProviderCreateFunc

type ProviderCreateFunc func(map[string]any) (Provider, E.Error)

type Webhook

type Webhook struct {
	ProviderBase
	Template  string `json:"template"`
	Payload   string `json:"payload"`
	Method    string `json:"method"`
	MIMEType  string `json:"mime_type"`
	ColorMode string `json:"color_mode"`
}

func (*Webhook) GetMIMEType

func (webhook *Webhook) GetMIMEType() string

GetMIMEType implements Provider.

func (*Webhook) GetMethod

func (webhook *Webhook) GetMethod() string

GetMethod implements Provider.

func (*Webhook) MakeBody

func (webhook *Webhook) MakeBody(logMsg *LogMessage) (io.Reader, error)

func (*Webhook) Validate

func (webhook *Webhook) Validate() E.Error

Jump to

Keyboard shortcuts

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