core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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 FormatEvent

func FormatEvent(req *http.Request, triggerType TriggerType) (interface{}, error)

FormatEvent Format event according to given trigger type, if trigger type if not HTTP, then we assume that event has already been formatted by event-source.

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 IsJSON

func IsJSON(bytes []byte) bool

IsJSON returns true if the input is a valid JSON message.

func IsRejectedRequest

func IsRejectedRequest(request *http.Request) bool

func SetHeaders

func SetHeaders(input, output http.Header)

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 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       interface{}      `json:"event"`
	Context     ExecutionContext `json:"context"`
	HandlerName string           `json:"handlerName"`
	HandlerPath string           `json:"handlerPath"`
	TriggerType TriggerType      `json:"-"`
}

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 interface{}, ctx ExecutionContext, triggerType TriggerType) (*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.

type TriggerType

type TriggerType string

TriggerType Enumeration of valid trigger types supported by runtime.

var (
	// TriggerTypeHTTP Event trigger of type HTTP.
	TriggerTypeHTTP TriggerType = "http"

	// ValidTriggerTypes List of supported trigger types.
	ValidTriggerTypes = []TriggerType{TriggerTypeHTTP}
)

func GetTriggerType

func GetTriggerType(triggerType string) (TriggerType, error)

GetTriggerType check that a given trigger type is supported by runtime.

Jump to

Keyboard shortcuts

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