context

package
v0.0.0-...-c5bcced Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

The global context package enables reading the request and sending a response.

// Pipe the request body to the response.
context.req.body.pipe(context.res.body);

// Or let the response consume the request.
context.res.body.consume(context.req.body);

// And set http response headers.
context.head('Content-Type', 'application/pdf');
context.head('Content-Description', 'File Transfer');
context.head('Content-Transfer-Encoding', 'binary');
context.head('Content-Disposition', 'inline; filename="demo.pdf"');

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(orb *orbit.Orbit) interface{}

Types

type Module

type Module struct {

	// Req represents the http request of the
	// function runtime, enabling processing
	// the http request details and data.
	Req *Request `console:"req"`

	// Res represents the http response of the
	// function runtime, enabling sending data
	// back to the requesting http client.
	Res *Response `console:"res"`
	// contains filtered or unexported fields
}

func (*Module) Cbor

func (this *Module) Cbor(data interface{})

func (*Module) Failure

func (this *Module) Failure()

Failure enables sending only an http 400 failure status code to the http client.

func (*Module) Head

func (this *Module) Head(key, val string)

Head enables defining the http headers which are to be sent with the response.

func (*Module) Html

func (this *Module) Html(data interface{})

func (*Module) Json

func (this *Module) Json(data interface{})

func (*Module) Pack

func (this *Module) Pack(data interface{})

func (*Module) Render

func (this *Module) Render(file string, args ...interface{})

func (*Module) Status

func (this *Module) Status(code int) *Status

Status enables defining the http status code, with a chained method to send the data using different encoding types.

func (*Module) Success

func (this *Module) Success()

Success enables sending only an http 200 success status code to the http client.

func (*Module) Text

func (this *Module) Text(data interface{})

func (*Module) Xml

func (this *Module) Xml(data interface{})

type Request

type Request struct {

	// Body represents the http request body of the
	// current function request. THe body can be
	// read or streamed as needed.
	Body *stream.Reader `console:"body"`

	// Head is an object containing the http
	// headers of the current request.
	Head map[string]string `console:"head"`

	// Method is the http method used when making
	// this request. It should be one of GET, PUT,
	// POST, PATCH, DELETE, TRACE, OPTIONS, HEAD.
	Method string `console:"method"`

	// User is the basic auth username used for
	// this request. If no username was specified
	// or no basic auth details were used then
	// this will ne an empty string.
	User string `console:"user"`

	// Pass is the basic auth password used for
	// this request. If no password was specified
	// or no basic auth details were used then
	// this will ne an empty string.
	Pass string `console:"pass"`

	// Host is the specific of the web host name
	// used when requesting this function request.
	Host string `console:"host"`

	// Path is the specific path used when running
	// this function. If the request was without a
	// url path, then this will be an empty string.
	Path string `console:"path"`

	// If the request url of the current request
	// contains any query paramaters, then this will
	// be populated with the full http query string.
	Query string `console:"query"`

	// IP is the parsed ipv4 or ipv6 address of the
	// client who has made the http request. It will
	// always be specified, and will never be empty.
	IP string `console:"ip"`
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(orb *orbit.Orbit) *Request

type Response

type Response struct {

	// Body represents the http response body of the
	// current function request. The body can be
	// can be written or streamed to.
	Body *stream.Writer `console:"body"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(orb *orbit.Orbit) *Response

type Status

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

func NewStatus

func NewStatus(orb *orbit.Orbit, req *Request, res *Response, val int) *Status

func (*Status) Cbor

func (this *Status) Cbor(data interface{})

func (*Status) Done

func (this *Status) Done()

func (*Status) Head

func (this *Status) Head(key, val string) *Status

func (*Status) Html

func (this *Status) Html(data interface{})

func (*Status) Json

func (this *Status) Json(data interface{})

func (*Status) Pack

func (this *Status) Pack(data interface{})

func (*Status) Text

func (this *Status) Text(data interface{})

func (*Status) Xml

func (this *Status) Xml(data interface{})

Jump to

Keyboard shortcuts

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