flash

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package flash provides experimental request-scoped flash message helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(ctx context.Context, messages ...Message) context.Context

Add stores messages on the context, creating a request store when needed.

func Flash

func Flash(ctx ...*partial.RenderContext) template.HTML

Flash renders flash messages for a render context with the default template.

go-doc:sig func() html/template.HTML

func FlashTarget

func FlashTarget(ctx ...*partial.RenderContext) template.HTML

FlashTarget renders the default flash target container.

go-doc:sig func() html/template.HTML

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns placeholders for flash template helpers.

func Has

func Has(ctx context.Context) bool

Has reports whether the context has flash messages.

func HasFlashes

func HasFlashes(ctx ...*partial.RenderContext) bool

HasFlashes reports whether a render context has request-scoped flash messages.

go-doc:sig func() bool

func Stage

func Stage(opts ...Option) partial.RenderStage

Stage installs flash template helpers.

func WithStore

func WithStore(ctx context.Context, store *Store) context.Context

WithStore stores an app-owned flash store on the context.

Types

type Data

type Data struct {
	Messages []Message
	TargetID string
}

Data is passed to the flash template.

type Level

type Level string

Level describes the intent of a flash message.

const (
	LevelSuccess Level = "success"
	LevelInfo    Level = "info"
	LevelWarn    Level = "warn"
	LevelError   Level = "error"
)

type Message

type Message struct {
	Level Level
	Text  string
}

Message is one request-scoped flash message.

func Drain

func Drain(ctx context.Context) []Message

Drain removes and returns the current context flash messages.

func Error

func Error(text string) Message

Error creates an error flash message.

func Flashes

func Flashes(ctx ...*partial.RenderContext) []Message

Flashes returns request-scoped flash messages for a render context.

go-doc:sig func() []github.com/donseba/go-partial/exp/flash.Message

func Info

func Info(text string) Message

Info creates an informational flash message.

func Messages

func Messages(ctx context.Context) []Message

Messages returns the current context flash messages.

func New

func New(level Level, text string) Message

New creates a flash message with the provided level and text.

func Success

func Success(text string) Message

Success creates a success flash message.

func Warn

func Warn(text string) Message

Warn creates a warning flash message.

type Option

type Option func(*options)

Option configures the flash renderer.

func WithPartial

func WithPartial(p *partial.Partial) Option

WithPartial renders flash messages with a user-provided partial.

func WithTargetID

func WithTargetID(id string) Option

WithTargetID changes the DOM ID used by the default flash target and the data passed to flash templates.

func WithTargetPartial

func WithTargetPartial(p *partial.Partial) Option

WithTargetPartial renders flashTarget with a user-provided partial.

func WithTargetTemplate

func WithTargetTemplate(path string) Option

WithTargetTemplate renders flashTarget with a user template from the active partial tree filesystem.

func WithTemplate

func WithTemplate(path string) Option

WithTemplate renders flash messages with a user template from the active partial tree filesystem.

type Store

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

Store holds flash messages for one request or app-owned session handoff.

Store is safe for concurrent Add, Messages, and Drain calls, but most applications should still treat a store as request/session-owned state.

func FromContext

func FromContext(ctx context.Context) *Store

FromContext returns the flash store from ctx, if present.

func NewStore

func NewStore(messages ...Message) *Store

NewStore creates an empty flash store.

func (*Store) Add

func (s *Store) Add(messages ...Message)

Add appends messages to the store.

func (*Store) Drain

func (s *Store) Drain() []Message

Drain removes and returns all messages.

func (*Store) Messages

func (s *Store) Messages() []Message

Messages returns a snapshot of the current messages.

Jump to

Keyboard shortcuts

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