webcontext

package
v0.0.0-...-86643de Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: BSD-2-Clause Imports: 9 Imported by: 2

Documentation

Overview

The webcontext package is Goweb's implementation of the Context object.

If you plan to write unit tests, see also the http://godoc.org/github.com/stretchr/goweb/webcontext/test package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WebContext

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

WebContext is a real context.Context that represents a single request.

You can use the goweb/webcontext/test package to easily and quickly generate test versions of the WebContext. See http://godoc.org/github.com/stretchr/goweb/webcontext/test for more information.

func NewWebContext

func NewWebContext(responseWriter http.ResponseWriter, request *http.Request, codecService codecsservices.CodecService) *WebContext

NewWebContext creates a new WebContext with the given request and response objects.

func (*WebContext) CodecOptions

func (c *WebContext) CodecOptions() objx.Map

CodecOptions gets a map of options to pass to codecs when responding.

func (*WebContext) CodecService

func (c *WebContext) CodecService() codecsservices.CodecService

CodecService gets the codecsservices.CodecService that this Context will use to marshal and unmarshal data to and from objects.

func (*WebContext) Data

func (c *WebContext) Data() objx.Map

Data gets a map of data about the context.

func (*WebContext) FileExtension

func (c *WebContext) FileExtension() string

FileExtension gets the extension of the file from the HttpRequest().

func (*WebContext) FormParams

func (c *WebContext) FormParams() objx.Map

FormParams gets the parameters that were posted in the request body and were present in the URL query.

Goweb gives you access to different types of parameters:

QueryParams - Parameters only from the URL query string
PostParams  - Parameters only from the body
FormParams  - Parameters from both the body AND the URL query string
PathParams  - Parameters from the path itself (i.e. /people/123)

func (*WebContext) FormValue

func (c *WebContext) FormValue(keypath string) string

FormValue gets a single value for the specified keypath from the form body and URL query. If there are multiple values the first value is returned.

func (*WebContext) FormValues

func (c *WebContext) FormValues(keypath string) []string

FormValues gets an array of the values for the specified keypath from the form body in the request and the URL query.

func (*WebContext) HttpRequest

func (c *WebContext) HttpRequest() *http.Request

HttpRequest gets the underlying http.Request that this Context represents.

func (*WebContext) HttpResponseWriter

func (c *WebContext) HttpResponseWriter() http.ResponseWriter

HttpResponseWriter gets the underlying http.ResponseWriter that will be used to respond to this request.

func (*WebContext) MethodString

func (c *WebContext) MethodString() string

MethodString gets the HTTP method of this request as an uppercase string.

If a "method" parameter is specified in the URL, it will be used. Otherwise, the method of the HTTP request itself will be used.

func (*WebContext) Path

func (c *WebContext) Path() *paths.Path

Path gets the paths.Path of the request.

func (*WebContext) PathParam

func (c *WebContext) PathParam(keypath string) string

DEPRECATED: Use PathValue instead.

PathParam gets the parameter from PathParams() with the specified keypath.

func (*WebContext) PathParams

func (c *WebContext) PathParams() objx.Map

PathParams gets any parameters that were pulled from the URL path. // Goweb gives you access to different types of parameters:

QueryParams - Parameters only from the URL query string
PostParams  - Parameters only from the body
FormParams  - Parameters from both the body AND the URL query string
PathParams  - Parameters from the path itself (i.e. /people/123)

func (*WebContext) PathValue

func (c *WebContext) PathValue(keypath string) string

PathValue gets the parameter from PathParams() with the specified key.

func (*WebContext) PostParams

func (c *WebContext) PostParams() objx.Map

PostParams gets the parameters that were posted in the request body.

Goweb gives you access to different types of parameters:

QueryParams - Parameters only from the URL query string
PostParams  - Parameters only from the body
FormParams  - Parameters from both the body AND the URL query string
PathParams  - Parameters from the path itself (i.e. /people/123)

func (*WebContext) PostValue

func (c *WebContext) PostValue(keypath string) string

PostValue gets a single value for the specified keypath from the form body. If there are multiple values the first value is returned.

func (*WebContext) PostValues

func (c *WebContext) PostValues(keypath string) []string

FormValues gets an array of the values for the specified keypath from the form body in the request.

func (*WebContext) QueryParams

func (c *WebContext) QueryParams() objx.Map

QueryParams gets the query parameters that are present after the ? in the URL.

Goweb gives you access to different types of parameters:

QueryParams - Parameters only from the URL query string
PostParams  - Parameters only from the body
FormParams  - Parameters from both the body AND the URL query string
PathParams  - Parameters from the path itself (i.e. /people/123)

func (*WebContext) QueryValue

func (c *WebContext) QueryValue(keypath string) string

QueryValue gets a single value for the specified key from the QueryParams. If there are multiple values (i.e. `?name=Mat&name=Laurie`), the first value is returned.

func (*WebContext) QueryValues

func (c *WebContext) QueryValues(keypath string) []string

QueryValues gets an array of the values for the specified key from the QueryParams.

Returns []string because in URLs it's possible to have multiple values for the same key, for example; ?name=Mat&name=Laurie&name=Tyler.

func (*WebContext) RequestBody

func (c *WebContext) RequestBody() ([]byte, error)

RequestBody gets the byte data out of the body of the request.

func (*WebContext) RequestData

func (c *WebContext) RequestData() (interface{}, error)

RequestData gets the data out of the body of the request as a usable object.

func (*WebContext) RequestDataArray

func (c *WebContext) RequestDataArray() ([]interface{}, error)

RequestDataArray gets the RequestData as an []interface{} for ease.

func (*WebContext) SetHttpRequest

func (c *WebContext) SetHttpRequest(httpRequest *http.Request)

SetHttpRequest sets the HttpRequest that represents the original request that issued the interaction. This is set automatically by Goweb, but can be overridden for advanced cases.

func (*WebContext) SetHttpResponseWriter

func (c *WebContext) SetHttpResponseWriter(responseWriter http.ResponseWriter)

SetHttpResponseWriter sets the HttpResponseWriter that will be used to respond to the request.

This is set by Goweb, but can be overridden if you want to intercept the usual writes to do something lower level with them. For example, save the response in memory for testing or logging purposes.

For production, if you set your own ResponseWriter, be sure to also write the response to the original ResponseWriter so that clients actually receive it. You can get the original ResponseWriter by calling the HttpResponseWriter() method on this object.

Directories

Path Synopsis
Package that enables you to write unit tests that rely on a context.Context object.
Package that enables you to write unit tests that rely on a context.Context object.

Jump to

Keyboard shortcuts

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