handlers

package
v0.0.0-...-79ea3da Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySessionTokenMessage = "authenticatedTokenMessage"
	KeySessionFlash        = "flash"
	KeySessionRedirectPath = "redirectPathAfterLogin"
)

Variables

This section is empty.

Functions

func HumanDate

func HumanDate(t time.Time) string

Create a humanDate function which returns a nicely formatted string representation of a time.Time object.

func NewTemplateCache

func NewTemplateCache(dir string) (map[string]*template.Template, error)

Types

type Application

type Application struct {
	DebugOn       bool
	ErrorLog      *log.Logger
	InfoLog       *log.Logger
	Session       *sessions.Session
	TemplateCache map[string]*template.Template
	Snippets      models.APISnippets
	Users         models.APIUsers
}

Application Define a struct to hold the application-wide dependencies for the web application. This will allow us to make the objects available to our handlers.

func (*Application) Routes

func (app *Application) Routes() http.Handler

Update the signature for the routes() method so that it returns a http.Handler instead of *http.ServeMux.

type TemplateData

type TemplateData struct {
	CSRFToken       string
	CurrentYear     int
	Flash           string
	Form            *forms.Form
	IsAuthenticated bool
	IsAdmin         bool
	LoggedInName    string
	ID              int
	Snippet         *models.Snippet
	Snippets        []*models.Snippet
	User            *models.User
	Users           []*models.User
	Roles           []*models.RoleType
}

Define a templateData type to act as the holding structure for any dynamic data that we want to pass to our HTML templates.

Jump to

Keyboard shortcuts

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