Documentation
¶
Index ¶
- Variables
- func HydrateHTTPResponse(resp http.ResponseWriter, body json.RawMessage, statusCode int)
- func IsJSON(bytes []byte) bool
- func IsRejectedRequest(request *http.Request) bool
- func SetHeaders(input, output http.Header)
- type APIGatewayProxyRequest
- type APIGatewayProxyRequestContext
- type CoreRuntimeRequest
- type ExecutionContext
- type FunctionInvoker
- type ResponseHTTP
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotSupportedTrigger Error when event is assigned to not supported trigger types. ErrNotSupportedTrigger = errors.New("trigger Type is not supported by Scaleway Functions Runtime") // ErrReadBody returned if body read returns error ErrReadBody = errors.New("unable to read request body") )
var ( // ErrInvalidHTTPResponseFormat Error type for mal-formatted responses from handler. ErrInvalidHTTPResponseFormat = errors.New("handler result for HTTP response is mal-formatted") // ErrRespEmpty is returned if we try to read a nil response. ErrRespEmpty = errors.New("http response is empty") )
Functions ¶
func HydrateHTTPResponse ¶
func HydrateHTTPResponse(resp http.ResponseWriter, body json.RawMessage, statusCode int)
HydrateHttpResponse will try to fill the response writer with content of body. Addtionaly it adds Content-Length header, this has to by done always before any call to Write on the body.
func IsRejectedRequest ¶
func SetHeaders ¶
Types ¶
type APIGatewayProxyRequest ¶
type APIGatewayProxyRequest struct {
Resource string `json:"resource"` // The resource path defined in API Gateway
Path string `json:"path"` // The url path for the caller
HTTPMethod string `json:"httpMethod"`
Headers map[string]string `json:"headers"`
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
QueryStringParameters map[string]string `json:"queryStringParameters"`
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
PathParameters map[string]string `json:"pathParameters"`
StageVariables map[string]string `json:"stageVariables"`
RequestContext APIGatewayProxyRequestContext `json:"requestContext"`
Body string `json:"body"`
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
}
APIGatewayProxyRequest contains data coming from the API Gateway proxy.
func FormatEvent ¶
func FormatEvent(req *http.Request) (APIGatewayProxyRequest, error)
FormatEvent Format event
func FormatEventHTTP ¶
func FormatEventHTTP(req *http.Request, bodyBytes []byte) APIGatewayProxyRequest
FormatEventHTTP converts a http.Request to internal APIGatewayProxyRequest object.
type APIGatewayProxyRequestContext ¶
type APIGatewayProxyRequestContext struct {
AccountID string `json:"accountId"`
ResourceID string `json:"resourceId"`
Stage string `json:"stage"`
RequestID string `json:"requestId"`
ResourcePath string `json:"resourcePath"`
Authorizer map[string]interface{} `json:"authorizer"`
HTTPMethod string `json:"httpMethod"`
APIID string `json:"apiId"` // The API Gateway rest API Id
}
APIGatewayProxyRequestContext contains the information to identify the AWS account and resources invoking the Lambda function. It also includes Cognito identity information for the caller.
type CoreRuntimeRequest ¶
type CoreRuntimeRequest struct {
Event APIGatewayProxyRequest `json:"event"`
Context ExecutionContext `json:"context"`
HandlerName string `json:"handlerName"`
HandlerPath string `json:"handlerPath"`
}
CoreRuntimeRequest - Structure for a request from core runtime to sub-runtime with event, context, and handler informations to dynamically import.
type ExecutionContext ¶
type ExecutionContext struct {
MemoryLimitInMB int `json:"memoryLimitInMb"`
FunctionName string `json:"functionName"`
FunctionVersion string `json:"functionVersion"`
}
ExecutionContext type for the context of execution of the function including memory, function name and version...
func GetExecutionContext ¶
func GetExecutionContext() ExecutionContext
GetExecutionContext is used to create a new execution context and make it available, for offline testing thoses values are definied by default and does not affect functions performance.
type FunctionInvoker ¶
type FunctionInvoker struct {
RuntimeBridge string
RuntimeBinary string
HandlerFilePath string
HandlerName string
IsBinary bool
// contains filtered or unexported fields
}
FunctionInvoker - In charge of running sub-runtime processes, and invoke it with all the necessary informations to bootstrap the language-specific wrapper to run function handlers.
func NewInvoker ¶
func NewInvoker( runtimeBinaryPath, runtimeBridgePath, handlerFilePath, handlerName, upstreamURL string, isBinaryHandler bool, ) (*FunctionInvoker, error)
NewInvoker Initialize runtime configuration to execute function handler
func (*FunctionInvoker) Execute ¶
func (fn *FunctionInvoker) Execute(event APIGatewayProxyRequest, ctx ExecutionContext) (*http.Request, error)
Execute a given function handler, and handle response.
func (*FunctionInvoker) StreamRequest ¶
func (fn *FunctionInvoker) StreamRequest(reqBody CoreRuntimeRequest) (*http.Request, error)
type ResponseHTTP ¶
type ResponseHTTP struct {
StatusCode int `json:"statusCode"`
Body json.RawMessage `json:"body"`
Headers map[string][]string `json:"headers"`
IsBase64Encoded bool `json:"isBase64Encoded"`
}
ResponseHTTP Type for HTTP triggers response emitted by function handlers.
func GetResponse ¶
func GetResponse(response *http.Response) (*ResponseHTTP, error)
GetResponse Transform a response string into an HTTP Response structure.