context

package
v0.0.0-...-932fd32 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// RequestContentLength contains a count of incoming bytes.
	RequestContentLength int
	// ResponseContentLength contains a count of outgoing bytes.
	ResponseContentLength int

	Input          *Input
	Output         *Output
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	Params         httprouter.Params
	// contains filtered or unexported fields
}

Context is created on every request and models the event, or request. The webserver will populate a RequestContext with any data provided by the client from a form, URL, or recognized data type sent in the request body.

func New

func New(w http.ResponseWriter, req *http.Request, params httprouter.Params) *Context

New produces a new request context event.

func (*Context) BadRequest

func (c *Context) BadRequest(output interface{})

BadRequest issues a bad request

func (*Context) Dump

func (c *Context) Dump(v interface{})

Dump spews the provided value to the stdout and is useful for debugging.

func (*Context) HTML

func (c *Context) HTML(output string) error

HTML outputs the provided HTML string

func (*Context) HTMLTemplate

func (c *Context) HTMLTemplate(name string, args interface{}) error

HTMLTemplate renders the HTML view specified by it's filename omitting the file extension.

func (*Context) InternalError

func (c *Context) InternalError(output interface{})

InternalError issues a 500 Internal Server Errror

type Input

type Input struct {
	Params      map[string]string
	ContentType string
	Format      string // html, xml, json, plain, etc...
	RequestBody []byte
	Request     *http.Request
}

Input represents the incoming request made from a client

func NewInput

func NewInput(req *http.Request) *Input

NewInput returns a new Webserver/context Input struct that provides useful behavior for working with HTTP requests.

func (*Input) Body

func (input *Input) Body() []byte

Body returns the request body data as bytes and sets the content into the Input.RequestBody field.

func (*Input) Cookie

func (input *Input) Cookie(key string) string

Cookie returns the provided cookie by name. If the cookie does not exist an empty string is returned.

func (*Input) Header

func (input *Input) Header(key string) string

Header returns value of a given request header

func (*Input) Host

func (input *Input) Host() string

Host returns host name. If the host info is unavailable localhost is returned.

func (*Input) IP

func (input *Input) IP() string

IP returns the IP address of the client. If this is a proxy request the first proxy IP is returned. If an error occurs the local IPv4 127.0.0.1 address is returned.

func (*Input) Is

func (input *Input) Is(method string) bool

Is returns boolean of this request is on given method, such as Is("POST").

func (*Input) IsAjax

func (input *Input) IsAjax() bool

IsAjax returns boolean of this request is generated by AJAX.

func (*Input) IsFormat

func (input *Input) IsFormat(test string) bool

IsFormat returns true if the encoding format matches the test

func (*Input) IsSecure

func (input *Input) IsSecure() bool

IsSecure returns boolean of this request is in https.

func (*Input) IsUpload

func (input *Input) IsUpload() bool

IsUpload returns boolean of whether file uploads in this request or not..

func (*Input) IsWebsocket

func (input *Input) IsWebsocket() bool

IsWebsocket returns boolean of this request is in webSocket.

func (*Input) Method

func (input *Input) Method() string

Method returns the HTTP request method: Example: GET

func (*Input) Param

func (input *Input) Param(key string) string

Param returns router param by a given key.

func (*Input) Path

func (input *Input) Path() string

Path returns the full request path (without query string or fragment)

func (*Input) Port

func (input *Input) Port() int

Port returns request client port. when error or empty, return 80.

func (*Input) Protocol

func (input *Input) Protocol() string

Protocol returns the request protocl name: Example: HTTP1/1.1.

func (*Input) Proxy

func (input *Input) Proxy() []string

Proxy returns proxy client IPs as a slice of strings.

func (*Input) Query

func (input *Input) Query(key string) string

Query returns the value for a query param by name.

func (*Input) Refer

func (input *Input) Refer() string

Refer returns http referer header.

func (*Input) Scheme

func (input *Input) Scheme() string

Scheme returns request scheme as "http" or "https".

func (*Input) SubDomains

func (input *Input) SubDomains() string

SubDomains returns sub domain string. if aa.bb.domain.com, returns aa.bb .

func (*Input) URL

func (input *Input) URL() string

URL returns request URL path (without query string, fragment).

func (*Input) UserAgent

func (input *Input) UserAgent() string

UserAgent returns request client user agent string.

type Output

type Output struct {
	Status      int
	ContentType string
	Context     *Context
}

Output represents the response written to a client

func NewOutput

func NewOutput(c *Context) *Output

NewOutput returns a new Output

func (*Output) Body

func (output *Output) Body(content []byte)

Body sets response body content and writes it to the client.

func (*Output) Header

func (output *Output) Header(key string, value string)

Header writes a response header to the client

func (*Output) JSON

func (output *Output) JSON(data interface{}, indent bool) error

JSON is a conveinence method for writing JSON to the response body

Jump to

Keyboard shortcuts

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