flash

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const SessionKey = "hop_session_flash"

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages flash messages.

func NewManager

func NewManager(session *scs.SessionManager) *Manager

NewManager creates a new Manager instance.

func (*Manager) AsMessages

func (m *Manager) AsMessages(msg Message) []Message

AsMessages ensures we have a slice of messages by converting a single message to a slice if necessary

func (*Manager) Error

func (m *Manager) Error(ctx context.Context, content string, closeable bool, autoclose int)

Error adds an error flash message.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context) Messages

Get returns the flash messages from the session.

func (*Manager) Info

func (m *Manager) Info(ctx context.Context, content string, closeable bool, autoclose int)

Info adds an informational flash message.

func (*Manager) NewErrorMessage

func (m *Manager) NewErrorMessage(content string, closeable bool, autoclose int) Message

NewErrorMessage creates a new error flash message, but does not add it to the session.

func (*Manager) NewInfoMessage

func (m *Manager) NewInfoMessage(content string, closeable bool, autoclose int) Message

NewInfoMessage creates a new informational flash message, but does not add it to the session.

func (*Manager) NewSuccessMessage

func (m *Manager) NewSuccessMessage(content string, closeable bool, autoclose int) Message

NewSuccessMessage creates a new success flash message, but does not add it to the session.

func (*Manager) NewWarningMessage

func (m *Manager) NewWarningMessage(content string, closeable bool, autoclose int) Message

NewWarningMessage creates a new warning flash message, but does not add it to the session.

func (*Manager) ReplaceFlash

func (m *Manager) ReplaceFlash(ctx context.Context, flashes Messages)

ReplaceFlash replaces the flash messages in the session.

func (*Manager) Success

func (m *Manager) Success(ctx context.Context, content string, closeable bool, autoclose int)

Success adds a success flash message.

func (*Manager) Warning

func (m *Manager) Warning(ctx context.Context, content string, closeable bool, autoclose int)

Warning adds a warning flash message.

type Message

type Message struct {
	Type      MessageType // The type of message
	Content   string      // The message to display
	Closable  bool        // Closable by default; this flag makes it not closable
	AutoClose int         // Duration in milliseconds
}

Message represents a flash message.

func (Message) NotClosable

func (f Message) NotClosable() bool

NotClosable returns true if the flash message is not closable.

type MessageType

type MessageType string

MessageType represents the type of flash message.

const (
	// MessageTypeError is an error message
	MessageTypeError MessageType = "error"
	// MessageTypeSuccess is a success message
	MessageTypeSuccess MessageType = "success"
	// MessageTypeWarning is a warning message
	MessageTypeWarning MessageType = "warning"
	// MessageTypeInfo is an informational message
	MessageTypeInfo MessageType = "info"
)

type Messages

type Messages []Message

Messages is a slice of flash messages.

Jump to

Keyboard shortcuts

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