web

package
v0.0.0-...-baa204d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: AGPL-3.0 Imports: 21 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 for users
	UserService models.UserService

	// An ApplicationService is the interface with the database for applications
	ApplicationService models.ApplicationService

	// An RSVPService is the interface with the databsae for RSVPs
	RSVPService models.RSVPService

	// An AnnouncementService is the interface with the database for announcements
	AnnouncementService models.AnnouncementService

	// A RaffleService is the interface with the databse for raffles
	RaffleService models.RaffleService

	// 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

	// Holds the current application status
	Status status.Status
}

A Handler will route requests to their appropriate HandlerFunc.

func NewHandler

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.

func (*Handler) NewPage

func (h *Handler) NewPage(w http.ResponseWriter, r *http.Request, title string) (*Page, bool)

type Page

type Page struct {
	Title string

	// Current status of app
	Status status.Status

	// 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.

Jump to

Keyboard shortcuts

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