web

package
v3.1.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 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)
)

Functions

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 TextToHTML

func TextToHTML(text string) string

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

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server defines an instance of the Web server.

func NewServer

func NewServer(
	conf *config.Root,
	mm message.Manager,
	mh *msghub.Hub) *Server

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

func (*Server) Notify

func (s *Server) Notify() <-chan error

Notify allows the running Web server to be monitored for a fatal error.

func (*Server) Start

func (s *Server) Start(ctx context.Context, readyFunc func())

Start begins listening for HTTP requests

Jump to

Keyboard shortcuts

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