webapps

package
v0.0.0-...-e7b361f Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package webapps handles the creation of routes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

Handle responds to an HTTP request.

type Middleware

type Middleware func(Handle) Handle

Middleware envelops Handle to intercept HTTP requests and modify responses.

type WebApp

type WebApp struct {

	// OnError is called after a Handle returned an error.
	OnError func(writer http.ResponseWriter, request *http.Request, params httprouter.Params, err error)

	// OnPanic is called after a Handle panicked.
	OnPanic func(writer http.ResponseWriter, request *http.Request, params httprouter.Params, recoveryInfo interface{})

	// Router is the underlying router.
	Router *httprouter.Router
	// contains filtered or unexported fields
}

WebApp represents a web application or web site. Router gives access to the underlying router and its settings. OnError and OnPanic can be overwritten by custom functions to handle errors and panics.

func New

func New(host, port string) *WebApp

New returns a new WebApp. OnError and OnPanic are initalized with a default function for handling errors and panics, and can be overwritten by a custom function.

func (*WebApp) Middleware

func (w *WebApp) Middleware(middleware Middleware)

Middleware adds a function that is executed before any Handle is executed. Middlewares added after calling Route are ignored.

func (*WebApp) Route

func (w *WebApp) Route(path string, handle Handle, methods ...string)

Route associates a URL path with a Handle.

func (*WebApp) Start

func (w *WebApp) Start() error

Start starts the HTTP server.

func (*WebApp) StartWithTLS

func (w *WebApp) StartWithTLS(certificatePath, keyPath string) error

StartWithTLS starts the HTTP server with TLS (Transport Layer Security).

Jump to

Keyboard shortcuts

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