Help us shape the future of Go! Take the 2026 Go Developer Survey

notifications

package
v1.21.20 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package notifications provides database notification services that work across different database backends (PostgreSQL and Oracle).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DatabaseType is "postgres" or "oracle"
	DatabaseType string

	// PostgresConnectionString for PostgreSQL LISTEN/NOTIFY
	PostgresConnectionString string

	// For Oracle polling approach
	PollingInterval time.Duration

	// Table name for Oracle polling notifications
	PollingTableName string
}

Config holds configuration for the notification service SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: configuration for the notification service including DB type and polling settings

func DefaultConfig

func DefaultConfig(databaseType string) Config

DefaultConfig returns a default configuration SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: build a default notification service config for the given database type (pure)

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: enumerate supported database backends for notification routing (pure)

const (
	// DatabaseTypePostgres represents PostgreSQL database
	DatabaseTypePostgres DatabaseType = "postgres"
	// DatabaseTypeOracle represents Oracle database
	DatabaseTypeOracle DatabaseType = "oracle"
)

type Notification

type Notification struct {
	// Channel is the notification channel name
	Channel string

	// Payload contains the notification data (typically JSON)
	Payload string

	// Timestamp when the notification was received or created
	Timestamp time.Time
}

Notification represents a database notification event SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: database notification event carrying a channel name, payload, and timestamp

type NotificationQueueEntry

type NotificationQueueEntry struct {
	ID        models.DBVarchar `gorm:"primaryKey;not null;size:36"`
	Channel   models.DBVarchar `gorm:"size:255;not null;index"`
	Payload   models.DBText    `gorm:""`
	CreatedAt time.Time        `gorm:"not null;autoCreateTime"`
	Processed bool             `gorm:"default:false;not null;index"`
}

NotificationQueueEntry represents an entry in the notification polling table.

This model would be Oracle-reachable once wired up: factory.go's NewNotificationService selects PollingNotifier (not the Postgres LISTEN/NOTIFY notifier) whenever the configured database is Oracle. As of this fix, no other package imports api/notifications, so the polling path is not exercised by the running server today — but the fix belongs here regardless, both because it's the correct behavior and to keep this file honest for whoever wires it up next. Deliberately NOT tagged with `gorm:"column:..."`: result-set labels come back UPPERCASE from Oracle and lowercase from Postgres, and GORM matches labels to DBNames case-sensitively. An untagged field's DBName comes from the dialect's NamingStrategy (OracleNamingStrategy on Oracle), so the mapping holds on both engines; hardcoded lowercase tags silently zeroed every field on Oracle (#699). SEM@91a78cddb7a534f2bab0556c442437fe098eb4fb: DB row representing a pending or processed notification in the polling queue

func (NotificationQueueEntry) TableName

func (NotificationQueueEntry) TableName() string

TableName specifies the table name for NotificationQueueEntry SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: return the table name for the notification queue (pure)

type NotificationService

type NotificationService interface {
	// Subscribe starts listening for notifications on the specified channel.
	// It returns a channel that will receive notifications.
	// The caller should handle errors returned in the notifications channel's close.
	Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

	// Notify sends a notification on the specified channel.
	// For PostgreSQL, this uses pg_notify.
	// For Oracle, this inserts into a polling table.
	Notify(ctx context.Context, channel string, payload string) error

	// Close cleans up resources used by the notification service
	Close() error
}

NotificationService defines the interface for database notifications This abstraction allows the application to work with both PostgreSQL's LISTEN/NOTIFY mechanism and Oracle's polling-based approach. SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: interface for subscribing to and sending database notifications across DB backends

func NewNotificationService

func NewNotificationService(dbType DatabaseType, postgresConnStr string, db *sql.DB, gormDB *gorm.DB) (NotificationService, error)

NewNotificationService creates a notification service appropriate for the database type SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: build a notification service appropriate for the given database type

func NewNotificationServiceFromConfig

func NewNotificationServiceFromConfig(cfg Config, db *sql.DB, gormDB *gorm.DB) (NotificationService, error)

NewNotificationServiceFromConfig creates a notification service from configuration SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: build a notification service from a config struct

type PollingNotifier

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

PollingNotifier implements NotificationService using database polling This is used for Oracle ADB and other databases that don't support LISTEN/NOTIFY SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: DB-polling notification service for databases lacking LISTEN/NOTIFY support (mutates shared state)

func NewPollingNotifier

func NewPollingNotifier(db *gorm.DB, pollInterval time.Duration) (*PollingNotifier, error)

NewPollingNotifier creates a new polling-based notification service SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: build and start a polling notification service against the given DB with the given interval (reads DB)

func (*PollingNotifier) Close

func (p *PollingNotifier) Close() error

Close implements NotificationService.Close SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: stop the polling loop and close all subscriber channels (mutates shared state)

func (*PollingNotifier) Notify

func (p *PollingNotifier) Notify(ctx context.Context, channel string, payload string) error

Notify implements NotificationService.Notify SEM@23998f331524274d028e5ec84e6d6b7d29d4e332: store a notification payload into the DB queue for polling delivery (reads DB)

func (*PollingNotifier) Subscribe

func (p *PollingNotifier) Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

Subscribe implements NotificationService.Subscribe SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: register a channel subscriber and return a notification channel; unsubscribe on context cancellation (mutates shared state)

type PostgresNotifier

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

PostgresNotifier implements NotificationService using PostgreSQL's LISTEN/NOTIFY SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: NotificationService backed by PostgreSQL LISTEN/NOTIFY with reconnect support

func NewPostgresNotifier

func NewPostgresNotifier(connStr string, db *sql.DB) (*PostgresNotifier, error)

NewPostgresNotifier creates a new PostgreSQL notification service SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: build and start a PostgreSQL LISTEN/NOTIFY notifier (reads DB)

func (*PostgresNotifier) Close

func (p *PostgresNotifier) Close() error

Close implements NotificationService.Close SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: stop the notification service, close all subscriber channels, and release the DB listener (mutates shared state)

func (*PostgresNotifier) Notify

func (p *PostgresNotifier) Notify(ctx context.Context, channel string, payload string) error

Notify implements NotificationService.Notify SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: dispatch a PostgreSQL LISTEN/NOTIFY message to a named channel (reads DB)

func (*PostgresNotifier) Subscribe

func (p *PostgresNotifier) Subscribe(ctx context.Context, channel string) (<-chan Notification, error)

Subscribe implements NotificationService.Subscribe SEM@a251f60c11fe9831021be2539ff7d746fbd65b2c: register a subscriber channel for a named notification channel, starting LISTEN if first (reads DB)

Jump to

Keyboard shortcuts

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