Closed benjaminhuo closed 2 years ago
As mentioned in @tpiperatgod’s plugin proposal: https://hackmd.io/XwHWmAJwQWeCu18zQ97s_A?view= , a few concerns here:
func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue
?func(w http.ResponseWriter, r *http.Request)
? How the []data is composed of for a Http function?context.GetInput
get all necessary HTTP parameters?func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue
, we might need to add func(*ofctx.OpenFunctionContext, CloudEvent) ofctx.RetValue
as wellAnother point is we might need to add a callback in the function signature?
It might not be proper to unify function type into one single func(*ofctx.OpenFunctionContext, []byte)
, the following function type should co-exist for different scenarios:
The question is do we need to add *ofctx.OpenFunctionContext
to sync functions
cloud event is becoming a standard in the serverless areas, we have to support cloud event type functions https://github.com/cloudevents/sdk-go
@tpiperatgod @wanjunlei
the function context is just call ctx context.Context
ctx context.Context: Provides runtime information for your Lambda function invocation. ctx is the variable you declare to leverage the information available via AWS Lambda context object in Go.
https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html https://docs.aws.amazon.com/lambda/latest/dg/golang-context.html
Valid handler signatures
You have several options when building a Lambda function handler in Go, but you must adhere to the following rules:
The handler must be a function.
The handler may take between 0 and 2 arguments. If there are two arguments, the first argument must implement context.Context.
The handler may return between 0 and 2 arguments. If there is a single return value, it must implement error. If there are two return values, the second value must implement error. For more information on implementing error-handling information, see AWS Lambda function errors in Go.
The following lists valid handler signatures. TIn and TOut represent types compatible with the encoding/json standard library. For more information, see func Unmarshal to learn how these types are deserialized.
func () func () error func (TIn) error func () (TOut, error) func (context.Context) error func (context.Context, TIn) error func (context.Context) (TOut, error) func (context.Context, TIn) (TOut, error)
Proposal created for this : https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/202112_functions_framework_refactoring.md
We need to refactor functions-framework with the following considerations: