Documentation ¶
Overview ¶
Package web provides the plumbing for Inbucket's web GUI and RESTful API
Index ¶
- Variables
- func FriendlyTime(t time.Time) template.HTML
- func Initialize(conf *config.Root, shutdownChan chan bool, mm message.Manager, mh *msghub.Hub)
- func ParseTemplate(name string, partial bool) (*template.Template, error)
- func RenderJSON(w http.ResponseWriter, data interface{}) error
- func RenderPartial(name string, w http.ResponseWriter, data interface{}) error
- func RenderTemplate(name string, w http.ResponseWriter, data interface{}) error
- func Reverse(name string, things ...interface{}) string
- func Start(ctx context.Context)
- func TextToHTML(text string) template.HTML
- func WrapURL(url string) string
- type Context
- type Handler
Constants ¶
This section is empty.
Variables ¶
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) )
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 ¶
FriendlyTime renders a timestamp in a friendly fashion: 03:04:05 PM if same day, otherwise Mon Jan 2, 2006
func Initialize ¶
Initialize sets up things for unit tests or the Start() method
func ParseTemplate ¶
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 TextToHTML ¶
TextToHTML takes plain text, escapes it and tries to pretty it up for HTML display
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 ¶
NewContext returns a Context for the given HTTP Request