utils

package
v0.0.0-...-e6a2f8b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeneralPrefix = "ns-" // general notification prefix
)

Variables

This section is empty.

Functions

func RandStrings

func RandStrings(n int) string

Types

type Builder

type Builder struct {
	Kind    Kind
	Title   string
	From    string
	Message string
	Level   v1.Type
}

Builder is the struct that contains the notification information.

func (*Builder) AddToEventQueue

func (nb *Builder) AddToEventQueue(neq *NoticeEventQueue)

AddToEvents adds the notification to the provided NoticeEventQueue.

func (*Builder) WithFrom

func (nb *Builder) WithFrom(from string) *Builder

func (*Builder) WithLevel

func (nb *Builder) WithLevel(Level v1.Type) *Builder

func (*Builder) WithMessage

func (nb *Builder) WithMessage(message string) *Builder

func (*Builder) WithTitle

func (nb *Builder) WithTitle(title string) *Builder

func (*Builder) WithType

func (nb *Builder) WithType(kind Kind) *Builder

type Event

type Event struct {
	// ID is the unique ID of the notification.
	ID      string
	Title   string
	From    string
	Message string
	Kind    Kind
	Level   v1.Type
}

Event is the struct that contains the notification information.

func NewNotificationEvent

func NewNotificationEvent(title string, message string, kind Kind, from string, level v1.Type) Event

NewNotificationEvent creates a new NotificationEvent with the provided title, message, kind, sender (from), and optional severity level.

Parameters: - title: The title of the notification. - message: The message content of the notification. - kind: The kind of the notification (e.g., General, Personal, Admin). - from: The sender of the notification. - level: The optional severity level of the notification. - target: An optional parameter specifying the intended recipient(s) of the notification. If provided, the notification will be directed towards these targets.

Return values: - A NotificationEvent struct populated with the provided values and a unique ID generated for this notification. - An error object if the provided level exceeds 1, in which case an error message "level parameter cannot exceed 1" will be returned.

The function also generates a unique ID for each NotificationEvent. If the generation of the ID fails, it uses the current Unix timestamp as the ID.

type Kind

type Kind string
const (
	General Kind = "General"
	Admin   Kind = "Admin"
)

type Manager

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

func NewNotificationManager

func NewNotificationManager(ctx context.Context, client client.Client,
	logger logr.Logger, batchSize, channelSize int) *Manager

func (*Manager) Load

func (nm *Manager) Load(receivers *Receiver, events []Event) *Manager

func (*Manager) Run

func (nm *Manager) Run()

Run of the NotificationManager runs the notification manager. It writes the notifications in batches

type NoticeEventQueue

type NoticeEventQueue struct {
	Events []Event
}

NotificationPackage is the struct that contains the notification information.

type Pool

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

func NewPool

func NewPool(size int) *Pool

func (*Pool) Add

func (p *Pool) Add(f func())

func (*Pool) Run

func (p *Pool) Run(size int)

func (*Pool) Wait

func (p *Pool) Wait()

type Receiver

type Receiver struct {
	context.Context
	client.Client
	// contains filtered or unexported fields
}

Receiver is the struct that contains the notification information.

func NewReceiver

func NewReceiver(ctx context.Context, client client.Client) *Receiver

func (*Receiver) AddReceiver

func (rv *Receiver) AddReceiver(receiver string) *Receiver

func (*Receiver) AddReceivers

func (rv *Receiver) AddReceivers(receivers []string) *Receiver

Cache of the NamespaceCache caches the namespaces in the cluster categorized by filters.

Jump to

Keyboard shortcuts

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