responder

package
v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package responder contains all the general functionality necessary for responding to a given server request: template setup, user auth checks, rendering of pages to an http.ResponseWriter

Index

Constants

This section is empty.

Variables

View Source
var (
	// Layout holds the base site layout template.  Handlers should clone and use
	// this for parsing their specific page templates
	Layout *tmpl.TRoot

	// InsufficientPrivileges is a simple page to declare to a user they are not
	// allowed to visit a certain page or perform a certain action
	InsufficientPrivileges *tmpl.Template

	// Home (for now) is a very simple static welcome page
	Home *tmpl.Template

	// Empty holds a simple blank page for rendering the header/footer and often
	// a simple alert-style message
	Empty *tmpl.Template
)

Functions

func GetUserIP

func GetUserIP(req *http.Request) string

GetUserIP returns the IP address from Apache. NOTE: This definitely won't work when the app is exposed directly!

func GetUserLogin

func GetUserLogin(w http.ResponseWriter, req *http.Request) string

GetUserLogin returns the Apache-auth user or the debuguser argument if settings.DEBUG is true

func HTMLComment

func HTMLComment(s string) template.HTML

HTMLComment forces an HTML comment into the source (since Go templates strip these)

func InitRootTemplate

func InitRootTemplate(templatePath string)

InitRootTemplate sets up pre-parsed template data in Root

func MustHavePrivilege

func MustHavePrivilege(priv *user.Privilege, f http.HandlerFunc) http.Handler

MustHavePrivilege denies access to pages if there's no logged-in user, or there is a user but the user isn't allowed to perform a particular action

Types

type GenericVars

type GenericVars map[string]interface{}

GenericVars holds anything specialized that doesn't make sense to have in PageVars

type PageVars

type PageVars struct {
	Title   string
	Version string
	Alert   template.HTML
	Info    template.HTML
	User    *user.User
	Data    GenericVars
}

PageVars is the generic list of data all pages may need, and the catch-all "Data" map for specialized one-off data

type Responder

type Responder struct {
	Writer  http.ResponseWriter
	Request *http.Request
	Vars    *PageVars
}

Responder wraps common response logic

func Response

func Response(w http.ResponseWriter, req *http.Request) *Responder

Response generates a Responder with basic data all pages will need: request, response writer, and user

func (*Responder) Audit

func (r *Responder) Audit(action, msg string)

Audit stores an audit log in the database and logs to the command line if the database audit fails

func (*Responder) Error

func (r *Responder) Error(status int, msg string)

Error sets up the Alert var and sends the appropriate header to the browser. If msg is empty, the status text from the http package is used.

func (*Responder) Render

func (r *Responder) Render(t *tmpl.Template)

Render uses the responder's data to render the given template

Jump to

Keyboard shortcuts

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