flash

package
v0.0.0-...-699b668 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FlashSuccess is the context key for success flash messages
	FlashSuccess = "FlashSuccess"

	// FlashWarn is a context key for warning flash messages
	FlashWarn = "FlashWarn"

	// FlashErr is a context key for flash error message
	FlashErr = "FlashError"
)

Variables

This section is empty.

Functions

func AddFlashToCtx

func AddFlashToCtx(ctx *base.Context, name, key string) error

AddFlashToCtx takes flash messages stored in a cookie which is associated with the request found in ctx, and puts them inside the ctx object. The flash messages can then be retrieved by calling ctx.Get( FlashKey).

NOTE When there are no flash messages then nothing is set.

Types

type Flash

type Flash struct {
	Kind    string
	Message string
}

Flash implements flash messages, like ones in gorilla/sessions

type Flasher

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

Flasher tracks flash messages

func New

func New() *Flasher

New creates new flasher. This alllows accumulation of lash messages. To save the flash messages the Save method should be called explicitly.

func (*Flasher) Add

func (f *Flasher) Add(kind, message string)

Add adds the flash message

func (*Flasher) Err

func (f *Flasher) Err(msg string)

Err adds error flash message

func (*Flasher) Save

func (f *Flasher) Save(ctx *base.Context, name, key string) error

Save saves flash messages to context

func (*Flasher) Success

func (f *Flasher) Success(msg string)

Success adds success flash message

func (*Flasher) Warn

func (f *Flasher) Warn(msg string)

Warn adds warning flash message

type Flashes

type Flashes []*Flash

Flashes is a collection of flash messages

func GetFlashes

func GetFlashes(ctx *base.Context, name, key string) (Flashes, error)

GetFlashes retieves all flash messages found in a cookie session associated with ctx..

name is the session name which is used to store the flash messages. The flash messages can be stored in any session, but it is a good idea to separate session for flash messages from other sessions.

key is the key that is used to identiry which flash messages are of interest.

Jump to

Keyboard shortcuts

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