announcements

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package announcements fetches an optional JSON feed of in-app messages from a remote URL and caches the latest payload in memory. The backend exposes this cache via an HTTP endpoint so the frontend can display a banner. Users can disable the feature entirely at any time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Feed

type Feed struct {
	Messages []Message `json:"messages"`
}

Feed is the top-level feed payload.

type Fetcher

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

Fetcher periodically pulls a remote JSON feed and caches the latest active message. "Active" means within the display window defined by published_at and show_until — pre-scheduled or expired messages are skipped, so a future message never shadows an active one lower in the feed.

func New

func New(feedURL string, interval time.Duration) *Fetcher

New creates a Fetcher. A zero or negative interval defaults to 10 minutes.

func (*Fetcher) Run

func (f *Fetcher) Run(ctx context.Context)

Run performs an initial fetch and then loops on a ticker until ctx is canceled. Failures are logged but do not stop the loop (the feed is best-effort).

func (*Fetcher) Snapshot

func (f *Fetcher) Snapshot() (*Message, time.Time)

Snapshot returns the currently cached message (or nil if none) plus the time of the last successful fetch.

type Message

type Message struct {
	ID            string                        `json:"id"`
	PublishedAt   string                        `json:"published_at"`
	ShowUntil     string                        `json:"show_until,omitempty"`
	CTAURL        string                        `json:"cta_url,omitempty"`
	DefaultLocale string                        `json:"default_locale,omitempty"`
	Translations  map[string]MessageTranslation `json:"translations,omitempty"`

	// Legacy flat fields (backward compat). Cleared after normalize().
	LegacyTitle    string `json:"title,omitempty"`
	LegacyBody     string `json:"body,omitempty"`
	LegacyCTALabel string `json:"cta_label,omitempty"`
}

Message is a single announcement entry. Fields match the JSON feed schema. Content is localized via the Translations map; the frontend picks the translation matching the user's current locale, falling back to DefaultLocale or the first available entry.

Legacy flat fields (title/body/cta_label) are accepted for backward compatibility with feeds that predate the translations map. They are normalized into a synthetic single-locale entry in Translations after unmarshal; see normalize().

type MessageTranslation

type MessageTranslation struct {
	Title    string `json:"title"`
	Body     string `json:"body,omitempty"`
	CTALabel string `json:"cta_label,omitempty"`
	CTAURL   string `json:"cta_url,omitempty"`
}

MessageTranslation holds the localized content for a single language.

Jump to

Keyboard shortcuts

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