web

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package web provides the plumbing for Inbucket's web GUI and RESTful API

Index

Constants

This section is empty.

Variables

View Source
var (

	// Router is shared between httpd, webui and rest packages. It sends
	// incoming requests to the correct handler function
	Router = mux.NewRouter()

	// ExpWebSocketConnectsCurrent tracks the number of open WebSockets
	ExpWebSocketConnectsCurrent = new(expvar.Int)
)
View Source
var TemplateFuncs = template.FuncMap{
	"friendlyTime": FriendlyTime,
	"reverse":      Reverse,
	"stringsJoin":  strings.Join,
	"textToHtml":   TextToHTML,
}

TemplateFuncs declares functions made available to all templates (including partials)

Functions

func FriendlyTime

func FriendlyTime(t time.Time) template.HTML

FriendlyTime renders a timestamp in a friendly fashion: 03:04:05 PM if same day, otherwise Mon Jan 2, 2006

func Initialize

func Initialize(
	conf *config.Root,
	shutdownChan chan bool,
	mm message.Manager,
	mh *msghub.Hub)

Initialize sets up things for unit tests or the Start() method

func ParseTemplate

func ParseTemplate(name string, partial bool) (*template.Template, error)

ParseTemplate loads the requested template along with _base.html, caching the result (if configured to do so)

func RenderJSON

func RenderJSON(w http.ResponseWriter, data interface{}) error

RenderJSON sets the correct HTTP headers for JSON, then writes the specified data (typically a struct) encoded in JSON

func RenderPartial

func RenderPartial(name string, w http.ResponseWriter, data interface{}) error

RenderPartial fetches the named template and renders it to the provided ResponseWriter.

func RenderTemplate

func RenderTemplate(name string, w http.ResponseWriter, data interface{}) error

RenderTemplate fetches the named template and renders it to the provided ResponseWriter.

func Reverse

func Reverse(name string, things ...interface{}) string

Reverse routing function (shared with templates)

func Start

func Start(ctx context.Context)

Start begins listening for HTTP requests

func TextToHTML

func TextToHTML(text string) template.HTML

TextToHTML takes plain text, escapes it and tries to pretty it up for HTML display

func WrapURL

func WrapURL(url string) string

WrapURL wraps a <a href> tag around the provided URL

Types

type Context

type Context struct {
	Vars       map[string]string
	Session    *sessions.Session
	MsgHub     *msghub.Hub
	Manager    message.Manager
	RootConfig *config.Root
	WebConfig  config.Web
	IsJSON     bool
}

Context is passed into every request handler function TODO remove redundant web config

func NewContext

func NewContext(req *http.Request) (*Context, error)

NewContext returns a Context for the given HTTP Request

func (*Context) Close

func (c *Context) Close()

Close the Context (currently does nothing)

type Handler

type Handler func(http.ResponseWriter, *http.Request, *Context) error

Handler is a function type that handles an HTTP request in Inbucket

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP builds the context and passes onto the real handler

Jump to

Keyboard shortcuts

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