lambda

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequestCtx

func NewRequestCtx(w http.ResponseWriter, r *http.Request) context.Context

NewRequestCtx adds request related data to r.Context(). You may use this at traditional http handler functions, and that is what happens at Lambda functions automatically. Returns new derived context. That can be used at client functions, silently propagating tracing headers.

E.g. ctx := NewRequestCtx(w, r)

func NewTestCtx

func NewTestCtx(method string, rawurl string, header http.Header, vars map[string]string) context.Context

NewTestCtx helps creating tests. Caller can define headers and path variables.

Types

type Lambda

type Lambda struct {

	// Status is the HTTP status code a function returnes with.
	// See ResponseStatus method for details.
	Status int

	// Trace contains the tracing data of the handler context.
	Trace tracedata.TraceData
	// contains filtered or unexported fields
}

Lambda is lambda class. Usually it is available via lambda function context and provides data for header manipulation. Often accessed as restful.L(ctx).

func L

func L(ctx context.Context) *Lambda

L returns lambda-related data from context.

func (*Lambda) RequestBasicAuth

func (l *Lambda) RequestBasicAuth() (username, password string, ok bool)

RequestBasicAuth returns the username and password provided in the request's Authorization header. Returned flag ok indicates if the header is received fine. That way one can tell if the header was received with empty strings or not.

func (*Lambda) RequestHeader

func (l *Lambda) RequestHeader() http.Header

RequestHeader returns the header map of received HTTP request.

func (*Lambda) RequestHeaderGet

func (l *Lambda) RequestHeaderGet(header string) string

RequestHeaderGet returns value of header in received HTTP request.

func (*Lambda) RequestHeaderValues

func (l *Lambda) RequestHeaderValues(header string) []string

RequestHeaderValues returns all the values of header in received HTTP request.

func (*Lambda) RequestMethod

func (l *Lambda) RequestMethod() string

RequestMethod returns request method

func (*Lambda) RequestQueryStringParameter

func (l *Lambda) RequestQueryStringParameter(parameter string) string

RequestQueryStringParameter returns value of given path parameter of received HTTP request.

func (*Lambda) RequestURL

func (l *Lambda) RequestURL() *url.URL

RequestURL returns URL of received HTTP request.

func (*Lambda) RequestVars

func (l *Lambda) RequestVars() map[string]string

RequestVars returns all the named path or query parameters of received HTTP request.

func (*Lambda) ResponseHeader

func (l *Lambda) ResponseHeader() http.Header

ResponseHeader return response header map to be sent. Usually used on testing.

func (*Lambda) ResponseHeaderAdd

func (l *Lambda) ResponseHeaderAdd(header, value string)

ResponseHeaderAdd adds an HTTP header to the response to be sent.

func (*Lambda) ResponseHeaderAddAs

func (l *Lambda) ResponseHeaderAddAs(header, value string)

ResponseHeaderAddAs adds an HTTP header to the response to be sent. Header is set as provided, not changed to canonical form. As long as there is no specific reason, use ResponseHeaderAdd instead.

func (*Lambda) ResponseHeaderSet

func (l *Lambda) ResponseHeaderSet(header, value string)

ResponseHeaderSet sets an HTTP header to the response to be sent.

func (*Lambda) ResponseStatus

func (l *Lambda) ResponseStatus(status int)

ResponseStatus sets HTTP status code to be sent. Use that if you want to set positive (non-error) status code.

restful.L(ctx).ResponseStatus(http.StatusAccepted)

Has no effect if lambda returns a non-nil error. In such case status is taken from the error (see restful.NewError), or 500 is returned.

func (*Lambda) TraceID

func (l *Lambda) TraceID() string

TraceID returns trace ID of Lambda context. That trace ID is either received in request or generated when Lambda context is created.

Jump to

Keyboard shortcuts

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