Documentation ¶
Index ¶
Constants ¶
const ( // AlertLvlDefault is used to render the default alert style. AlertLvlDefault = "" // AlertLvlPrimary is used to render an alert with our primary color. AlertLvlPrimary = "primary" // AlertLvlInfo is used to render an alert with general information. AlertLvlInfo = "info" // AlertLvlSuccess is used to render an alert with a success message. AlertLvlSuccess = "success" // AlertLvlWarning is used to render an alert with a warning message. AlertLvlWarning = "warning" // AlertLvlError is used to render an alert with an error message. AlertLvlError = "danger" // AlertLvlDark is used to render a dark-style alert. AlertLvlDark = "dark" // AlertLvlLink is used to render an alert with our link color. AlertLvlLink = "link" // AlertMsgErrGeneric is displayed when any arbitrary error is encountered by the backend. AlertMsgErrGeneric = "Something went wrong. Please try again, and contact us if the problem persists." )
const ( // LayoutsDir specifies where layout templates are stored. LayoutsDir string = "views/layouts/" // PartialsDir specifies where partials (small, reusable templates) are stored. PartialsDir string = "views/layouts/partials/" // TemplateDir specifies where any template might be found. TemplateDir string = "views/" // TemplateExt specifies the extension of our templates. TemplateExt string = ".gohtml" )
Variables ¶
This section is empty.
Functions ¶
func RedirectAlert ¶
RedirectAlert performs an http.Redirect after persisting the provided alert in a cookie so that it can be displayed when the new page is loaded.
Types ¶
type Alert ¶
type Alert struct { // Level can be one of the following: AlertLvlDefault, AlertLvlDark, AlertLvlPrimary, AlertLvlLink, AlertLvlInfo, // AlertLvlSuccess, AlertLvlWarning, or AlertLvlError. Level string // Message is the message which will be rendered in the alert. Message string }
Alert is used to render the alert template.
func NewAlert ¶
NewAlert returns an *Alert with the specified lvl and msg. For error alerts, use NewAlertErr instead.
func NewAlertErr ¶
NewAlertErr returns an *Alert with the AlertLvlError level. If err is a PublicError, then the corresponding public error message will be the alert's message; otherwise, the alert's message will be AlertMsgErrGeneric.
type Data ¶
Data is the top-level structure that views expect data to come in. Data intended for the yield template must be in the Yield field.
func (*Data) SetAlert ¶
SetAlert creates an Alert with the specified lvl and msg and sets it to d.Alert. For error alerts, use SetAlertErr instead.
func (*Data) SetAlertErr ¶
SetAlertErr creates an Alert with the AlertLvlError level and sets it to d.Alert. If the error is a PublicError, then the corresponding public error message will be the alert's message; otherwise, the alert's message will be AlertMsgErrGeneric.
type PublicError ¶
type PublicError interface { error // Public returns an error message which is acceptable for display to the user. // The message should not reveal internal system design to the user, should start with a capital letter, // and end with a period. Public() string }
PublicError defines an error type which can be safely displayed to the user.
type View ¶
View includes a template and layout file to be used to render views.
func (*View) Render ¶
func (v *View) Render(w http.ResponseWriter, r *http.Request, data interface{})
Render executes a template and renders the provided data in it. If data is not of views.Data type, Render moves the provided data to the Yield field of a Data struct so that users of Render need not create a Data struct. It uses a buffer to ensure complete writing of the executed template data to ResponseWriter.