webapp

package
v0.0.0-...-5c39df0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CsrfFormToken  = "_csrf_token"
	CsrfHttpHeader = "X-Csrf-Token"
	CsrfTokenKey   = "CsrfToken"
)
View Source
const (
	FlashMessageKey = "FlashMessage"
	FlashSuccessKey = "FlashSuccess"
	FlashWarningKey = "FlashWarning"
	FlashErrorKey   = "FlashError"
)

Variables

This section is empty.

Functions

func EncodeRandomKey

func EncodeRandomKey() string

func NewRouter

func NewRouter() *mux.Router

func RDebug

func RDebug(r *http.Request)

RDebug sets this request to be logged at DEBUG level rather than the INFO default. Useful, for example, for health check endpoints so that they don't flood production logs.

func RId

func RId(r *http.Request) string

func RLog

func RLog(r *http.Request) *slog.Logger

func RSet

func RSet(r *http.Request, key string, value any)

func RedirectTo

func RedirectTo(w http.ResponseWriter, r *http.Request, routeName string, pathVars ...string)

func RedirectToUrl

func RedirectToUrl(w http.ResponseWriter, r *http.Request, url string)

func Render

func Render(w http.ResponseWriter, r *http.Request, templateFile string, data map[string]any, opts ...RenderOpt)

func RenderError

func RenderError(w http.ResponseWriter, r *http.Request, err error, msg string, statusCode int)

func WithMiddleware

func WithMiddleware(h http.Handler, withTLS bool) http.Handler

Types

type CsrfProtection

type CsrfProtection int
const (
	CsrfDisabled CsrfProtection = iota
	CsrfPerRequest
	CsrfPerSession
)

type RenderOpt

type RenderOpt func(cfg *renderCfg)

func RenderWithContentType

func RenderWithContentType(contentType string) RenderOpt

func RenderWithLayoutFile

func RenderWithLayoutFile(layoutFile string) RenderOpt

func RenderWithStatusCode

func RenderWithStatusCode(statusCode int) RenderOpt

func RenderWithTemplateName

func RenderWithTemplateName(templateName string) RenderOpt

func RenderWithoutBuffer

func RenderWithoutBuffer() RenderOpt

type Session

type Session interface {
	Set(key string, value any)
	Get(key string) (any, bool)
	GetString(key string) string
	AddFlashMessage(msg string)
	AddFlashSuccess(msg string)
	AddFlashWarning(msg string)
	AddFlashError(msg string)
	Delete(key string)
	Clear()
}

func CurrentSession

func CurrentSession(r *http.Request) Session

type SessionStore

type SessionStore interface {
	Wrap(fn http.HandlerFunc) http.HandlerFunc
}

func NewSessionStore

func NewSessionStore(cookieName, authKey, encKey string, csrf CsrfProtection) (SessionStore, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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