webapps

package
v0.0.0-...-db10d9a Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2015 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequestHandlerFunc http.HandlerFunc = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	defer context.Clear(r)

	session := getSession(r)
	setSessionOptions(session)
	setCsrfToken(session)
	context.Set(r, "session", session)

	data := getDefaultTemplateData(r)
	context.Set(r, "data", data)

	setTranslateFuncs(r, data)
	SetCspHeader(w)

	w.Header().Set("Cache-Control", "no-cache, must-revalidate")

	if !isCsrfValid(r, session) {
		session.Save(r, w)
		http.Error(w, "Invalid CSRF token", http.StatusForbidden)
		log.Warning.Println("CSRF error")
		return
	}

	if UserSessionHandler != nil {
		UserSessionHandler(r, session)
	}

	sessionConfig.Routes.ServeHTTP(w, r)
})
View Source
var UserSessionHandler func(r *http.Request, session *sessions.Session)

Functions

func FlashMessage

func FlashMessage(r *http.Request, w http.ResponseWriter)

func GetFileServer

func GetFileServer(config FileServerConfig) httprouter.Handle

func GetFutureT

func GetFutureT(r *http.Request) i18n.FutureTranslateFunc

func GetStaticPath

func GetStaticPath(path string) string

func GetTemplate

func GetTemplate(name string, r *http.Request) *template.Template

func InitCsp

func InitCsp(config CspConfig)

func InitSessions

func InitSessions(config SessionConfig)

func InitTemplates

func InitTemplates(config TemplateConfig)

func SendResponse

func SendResponse(templateName string, r *http.Request, w http.ResponseWriter)

func SetCspHeader

func SetCspHeader(w http.ResponseWriter)

Types

type CspConfig

type CspConfig struct {
	Policies []string
}

type FileServerConfig

type FileServerConfig struct {
	Asset           func(name string) ([]byte, error)
	AssetDir        func(name string) ([]string, error)
	StaticFilesPath string
}

type SessionConfig

type SessionConfig struct {
	Routes http.Handler
	Secret string
}

type TemplateConfig

type TemplateConfig struct {
	Asset func(name string) ([]byte, error)
	Root  string
}

type TemplateData

type TemplateData map[string]interface{}

func GetTemplateData

func GetTemplateData(r *http.Request) TemplateData

Jump to

Keyboard shortcuts

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