respond

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, r *http.Request, code int, errorMessage string, fields logrus.Fields, err error)

Error displays the default error page.

func JSON

func JSON(l logrus.FieldLogger, w http.ResponseWriter, v interface{}, code int)

JSON formats a JSON response.

func NewPanicFormatter

func NewPanicFormatter(logger logrus.FieldLogger) negroni.PanicFormatter

NewPanicFormatter creates a formatter to display panics.

func Page

func Page(l logrus.FieldLogger, w http.ResponseWriter, tpl *template.Template, title string, sess SessionInfo, access page.AccessChecker, bodyData interface{})

Page formats a page-type response.

A page-type response is supposed to be a subpage (see the page package), and it sets strict CSP.

func Template

func Template(l logrus.FieldLogger, w http.ResponseWriter, tpl *template.Template, data interface{}, code int)

Template renders a html template.

Types

type ErrorPage

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

ErrorPage is an error page instance that will get rendered for the current request.

func DefaultErrorPage

func DefaultErrorPage(logger logrus.FieldLogger) *ErrorPage

DefaultErrorPage creates the default error page.

func NewErrorPage

func NewErrorPage(logger logrus.FieldLogger, tpl *template.Template) *ErrorPage

NewErrorPage creates a new ErrorPage.

func (*ErrorPage) FormatPanicError

func (p *ErrorPage) FormatPanicError(w http.ResponseWriter, r *http.Request, infos *negroni.PanicInformation)

FormatPanicError formats a panic for Negroni.

func (*ErrorPage) RespondError

func (p *ErrorPage) RespondError(w http.ResponseWriter, r *http.Request, code int, errorMessage string, fields logrus.Fields, err error)

RespondError writes the error page to the response writer.

type ErrorPageData

type ErrorPageData struct {
	Code    int
	Message string
}

ErrorPageData represents the data given to the error page template.

type SessionInfo

type SessionInfo interface {
	GetCSRFToken() string
	LoggedIn() bool
}

SessionInfo stores important information about the session.

Jump to

Keyboard shortcuts

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