flash

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default(config Config)

func Get

func Redirect

func Redirect(c router.Context, location string, data any, status ...int) error

func RedirectBack

func RedirectBack(c router.Context, fallback string, data router.ViewContext, status ...int) error

func RedirectToRoute

func RedirectToRoute(c router.Context, routeName string, data router.ViewContext, status ...int) error

func SetMessage added in v0.38.0

func SetMessage(c router.Context, msg Message) router.Context

func ToMiddleware

func ToMiddleware(f *Flash, key string) router.MiddlewareFunc

func WithData

func WithData(c router.Context, data router.ViewContext) router.Context

func WithError

func WithError(c router.Context, data router.ViewContext) router.Context

func WithInfo

func WithInfo(c router.Context, data router.ViewContext) router.Context

func WithSuccess

func WithSuccess(c router.Context, data router.ViewContext) router.Context

func WithWarn

func WithWarn(c router.Context, data router.ViewContext) router.Context

Types

type Config

type Config struct {
	Name        string    `json:"name"`
	Value       string    `json:"value"`
	Path        string    `json:"path"`
	Domain      string    `json:"domain"`
	MaxAge      int       `json:"max_age"`
	Expires     time.Time `json:"expires"`
	Secure      bool      `json:"secure"`
	HTTPOnly    bool      `json:"http_only"`
	SameSite    string    `json:"same_site"`
	SessionOnly bool      `json:"session_only"`

	// ClientAccessible controls whether the flash cookie can be read by client-side JavaScript.
	// Leave this false for SSR use-cases where middleware injects flash into templates.
	// Set this true for purely client-rendered UIs that need to read the cookie after redirects.
	ClientAccessible bool `json:"client_accessible"`

	// DefaultMessageTitle and DefaultMessageText are used when setting toast messages with
	// missing Title/Text fields.
	DefaultMessageTitle string `json:"default_message_title"`
	DefaultMessageText  string `json:"default_message_text"`
}

type Flash

type Flash struct {
	// contains filtered or unexported fields
}
var DefaultFlash *Flash

func New

func New(config Config) *Flash

func (*Flash) Get

func (*Flash) GetMessage added in v0.38.0

func (f *Flash) GetMessage(c router.Context) (*Message, bool)

func (*Flash) GetMessages added in v0.38.0

func (f *Flash) GetMessages(c router.Context) ([]Message, bool)

func (*Flash) Redirect

func (f *Flash) Redirect(c router.Context, location string, data any, status ...int) error

func (*Flash) RedirectBack

func (f *Flash) RedirectBack(c router.Context, fallback string, data router.ViewContext, status ...int) error

func (*Flash) RedirectToRoute

func (f *Flash) RedirectToRoute(c router.Context, routeName string, data router.ViewContext, status ...int) error

func (*Flash) SetMessage added in v0.38.0

func (f *Flash) SetMessage(c router.Context, msg Message) router.Context

func (*Flash) WithData

func (f *Flash) WithData(c router.Context, data router.ViewContext) router.Context

func (*Flash) WithError

func (f *Flash) WithError(c router.Context, data router.ViewContext) router.Context

func (*Flash) WithInfo

func (f *Flash) WithInfo(c router.Context, data router.ViewContext) router.Context

func (*Flash) WithSuccess

func (f *Flash) WithSuccess(c router.Context, data router.ViewContext) router.Context

func (*Flash) WithWarn

func (f *Flash) WithWarn(c router.Context, data router.ViewContext) router.Context

type Message added in v0.38.0

type Message struct {
	Type  string
	Title string
	Text  string
}

func GetMessage added in v0.38.0

func GetMessage(c router.Context) (*Message, bool)

func GetMessageFrom added in v0.38.0

func GetMessageFrom(data router.ViewContext) (*Message, bool)

func GetMessages added in v0.38.0

func GetMessages(c router.Context) ([]Message, bool)

func GetMessagesFrom added in v0.38.0

func GetMessagesFrom(data router.ViewContext) ([]Message, bool)

Jump to

Keyboard shortcuts

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