web

package
v0.0.0-...-a84961e Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown content type.
	Unknown = iota
	// JSON content type.
	JSON
	// Gobs content type.
	Gobs
	// Stream content type.
	Stream
)
View Source
const (
	// ContentType is used for retrieving and setting the Content-Type header.
	ContentType = "Content-Type"
	// JSONContent is used for setting the JSON Content-Type.
	JSONContent = "application/json"
)

Variables

View Source
var (
	// Debug gets set to 'true' if chatty logging is desired.
	Debug bool
)

Functions

func Wrap

func Wrap(handler func(*Context)) httprouter.Handle

Wrap the "httprouter" call for use with a context.

Types

type Context

type Context struct {
	W        http.ResponseWriter
	R        *http.Request
	PS       httprouter.Params
	User     string
	Password string
	// contains filtered or unexported fields
}

Context provides a simplified interface for handling responding and logging.

func New

func New(
	w http.ResponseWriter,
	r *http.Request,
	ps httprouter.Params,
	user string,
	password string,
) *Context

New Context constructor.

func (*Context) Debug

func (ctx *Context) Debug(v ...interface{})

Debug a message without a newline.

func (*Context) Debugf

func (ctx *Context) Debugf(format string, v ...interface{})

Debugf a formatted message.

func (*Context) Debugln

func (ctx *Context) Debugln(v ...interface{})

Debugln a message and a newline.

func (*Context) Decode

func (ctx *Context) Decode(v interface{}) error

Decode request into passed interface.

func (*Context) Log

func (ctx *Context) Log(v ...interface{})

Log a message without a newline.

func (*Context) Logf

func (ctx *Context) Logf(format string, v ...interface{})

Logf a formatted message.

func (*Context) Logln

func (ctx *Context) Logln(v ...interface{})

Logln a message and add a newline.

func (*Context) Reader

func (ctx *Context) Reader() io.Reader

Reader returns the request reader.

func (*Context) Respond

func (ctx *Context) Respond() *Response

Respond to the client. This is the sole constructor for a Response.

func (*Context) Writer

func (ctx *Context) Writer() io.Writer

Writer returns the response writer.

type Response

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

Response builder for HTTP requests.

func (*Response) Add

func (resp *Response) Add(key, value string) *Response

Add header to response.

func (*Response) Do

func (resp *Response) Do()

Do finalizes the response.

func (*Response) Status

func (resp *Response) Status(status int) *Response

Status code to be returned for the request.

func (*Response) Stream

func (resp *Response) Stream() io.Writer

Stream returns a writer for downloading. Do not call 'Do'.

func (*Response) With

func (resp *Response) With(msg interface{}) *Response

With the passed in message, encode and create response.

Jump to

Keyboard shortcuts

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