messages

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: GPL-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrRequestRequired      = errs.Error("messages: request required")
	ErrBackendNotConfigured = errs.Error("messages: backend not configured")
	ErrMessagesNotInstalled = errs.Error("messages: app not installed")
)
View Source
const (
	DEBUG   MessageTag = "debug"
	INFO    MessageTag = "info"
	SUCCESS MessageTag = "success"
	WARNING MessageTag = "warning"
	ERROR   MessageTag = "error"

	LEVEL_DEBUG   uint = 10
	LEVEL_INFO    uint = 20
	LEVEL_SUCCESS uint = 30
	LEVEL_WARNING uint = 40
	LEVEL_ERROR   uint = 50
)
View Source
const (
	APPVAR_COOKIE_KEY = "messages.cookieKey"
)

Variables

View Source
var DefaultTags = MessageTags{
	Debug:   DEBUG,
	Info:    INFO,
	Success: SUCCESS,
	Warning: WARNING,
	Error:   ERROR,
}

Functions

func AddMessage

func AddMessage(r *http.Request, tag MessageTag, message string, extraTags ...MessageTag) error

func ConfigureBackend

func ConfigureBackend(initBackend func(r *http.Request) (MessageBackend, error))

func Debug

func Debug(r *http.Request, message string, extraTags ...MessageTag) error

func Error

func Error(r *http.Request, message string, extraTags ...MessageTag) error

func Info

func Info(r *http.Request, message string, extraTags ...MessageTag) error

func MessagesMiddleware

func MessagesMiddleware(next mux.Handler) mux.Handler

func NewAppConfig

func NewAppConfig() django.AppConfig

func RequestMessageContext

func RequestMessageContext(c ctx.ContextWithRequest)

func SetLevel

func SetLevel(r *http.Request, level MessageTag) error

func Success

func Success(r *http.Request, message string, extraTags ...MessageTag) error

func Warning

func Warning(r *http.Request, message string, extraTags ...MessageTag) error

Types

type BaseMessage

type BaseMessage struct {
	Level       MessageTag   `json:"tag"`
	Text        string       `json:"message"`
	ExtraLevels []MessageTag `json:"extra"`
}

func (*BaseMessage) ExtraTags

func (m *BaseMessage) ExtraTags() []MessageTag

func (*BaseMessage) Message

func (m *BaseMessage) Message() string

func (*BaseMessage) Prepare

func (m *BaseMessage) Prepare() error

func (*BaseMessage) String

func (m *BaseMessage) String() string

func (*BaseMessage) Tag

func (m *BaseMessage) Tag() MessageTag

type CookieBackend

type CookieBackend struct {
	Request        *http.Request
	BaseCookie     *http.Cookie
	QueuedMessages []Message
	MinTagLevel    uint
	// contains filtered or unexported fields
}

func (*CookieBackend) Clear

func (d *CookieBackend) Clear() error

func (*CookieBackend) Finalize

func (d *CookieBackend) Finalize(w http.ResponseWriter, r *http.Request) error

func (*CookieBackend) Get

func (d *CookieBackend) Get() (messages []Message, AllRetrieved bool)

func (*CookieBackend) Level

func (d *CookieBackend) Level() MessageTag

func (*CookieBackend) SetLevel

func (d *CookieBackend) SetLevel(level MessageTag) error

func (*CookieBackend) Store

func (d *CookieBackend) Store(message Message) error

type Message

type Message interface {
	Tag() MessageTag
	Message() string
	ExtraTags() []MessageTag
	Prepare() error
}

func Messages

func Messages(r *http.Request) (messages []Message, AllRetrieved bool)

type MessageAppConfig

type MessageAppConfig struct {
	*apps.AppConfig

	Tags *MessageTags
	// contains filtered or unexported fields
}

func (*MessageAppConfig) ConfigureBackend

func (m *MessageAppConfig) ConfigureBackend(initBackend func(r *http.Request) (MessageBackend, error))

func (*MessageAppConfig) ConfigureTags

func (m *MessageAppConfig) ConfigureTags(tags MessageTags)

type MessageBackend

type MessageBackend interface {
	Get() (messages []Message, AllRetrieved bool)
	Store(message Message) error
	Level() MessageTag
	SetLevel(level MessageTag) error
	Finalize(w http.ResponseWriter, r *http.Request) error
	Clear() error
}

func Backend

func Backend(r *http.Request) MessageBackend

func BackendFromContext

func BackendFromContext(r *http.Request) MessageBackend

func NewCookieBackend

func NewCookieBackend(r *http.Request) (MessageBackend, error)

func NewSessionBackend

func NewSessionBackend(r *http.Request) (MessageBackend, error)

type MessageTag

type MessageTag string

func GetLevel

func GetLevel(r *http.Request) (MessageTag, error)

type MessageTags

type MessageTags struct {
	Debug   MessageTag
	Info    MessageTag
	Success MessageTag
	Warning MessageTag
	Error   MessageTag
}

func Tags

func Tags() *MessageTags

type SessionBackend

type SessionBackend struct {
	Request     *http.Request
	MinTagLevel uint
}

func (*SessionBackend) Clear

func (b *SessionBackend) Clear() error

func (*SessionBackend) Finalize

func (b *SessionBackend) Finalize(w http.ResponseWriter, r *http.Request) error

func (*SessionBackend) Get

func (b *SessionBackend) Get() (msgs []Message, AllRetrieved bool)

func (*SessionBackend) Level

func (b *SessionBackend) Level() MessageTag

func (*SessionBackend) SetLevel

func (b *SessionBackend) SetLevel(level MessageTag) error

func (*SessionBackend) Store

func (b *SessionBackend) Store(message Message) error

Jump to

Keyboard shortcuts

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