web

package
v0.0.0-...-ea8537e Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: AGPL-3.0 Imports: 18 Imported by: 0

README

web/

HTTP endpoints that serve HTML. We may not have many (any?) of these if we go for an API ortiented backend as we have in the past.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorReporter

type ErrorReporter func(interfaces ...interface{})

type Handler

type Handler struct {
	// A Mux handles all routing and middleware.
	*chi.Mux

	// A UserService is the interface with the database.
	UserService models.UserService

	// An ApplicationService is the interface with the databsae
	ApplicationService models.ApplicationService

	// A Mailer is used to send emails
	Mailer mail.Mailer

	// An S3 handles uploading files to S3
	S3 s3.S3

	// HTML templates to render
	Templates *template.Template

	// An ErrorReport reports errors to something like rollbar
	ErrReporter ErrorReporter

	// Stores session cookies
	SessionStore *sessions.CookieStore

	// Name cookie that stores sessions
	SessionCookieName string
}

A Handler will route requests to their appropriate HandlerFunc.

func NewHandler

func NewHandler(us models.UserService, as models.ApplicationService, mailer mail.Mailer, S3 s3.S3) *Handler

NewHandler creates a handler for web requests.

func (*Handler) Error

func (h *Handler) Error(w http.ResponseWriter, r *http.Request, err error, redirectPath string, interfaces ...interface{})

Error checks an error given to it. If it's a known error that we've made we can show it to the user as a flash. If it's unknown then we should tell the user that something went wrong and report the error to rollbar.

type Page

type Page struct {
	Title string

	// Current status of app
	Status string

	// A generic place to put unstructured data
	Data interface{}

	// An array of messages to show the user
	Flashes []flash.Flash

	// Values to be put back into a form when shown to a user again
	// For example, when they log in with the wrong password we want
	// the email they tried to log in with to persist
	FormRefill interface{}

	// The user's email, blank if user not logged in
	Email           string
	IsAuthenticated bool
}

A Page is all the data needed to render a page.

func NewPage

func NewPage(w http.ResponseWriter, r *http.Request, title string, status string, session *sessions.Session) (*Page, bool)

Jump to

Keyboard shortcuts

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