OpenFunction / functions-framework

functions-framework for multi-runtime, multi-type functions, and multi-language support
10 stars 6 forks source link

Functions framework refactoring #12

Closed benjaminhuo closed 2 years ago

benjaminhuo commented 2 years ago

We need to refactor functions-framework with the following considerations:

benjaminhuo commented 2 years ago

As mentioned in @tpiperatgod’s plugin proposal: https://hackmd.io/XwHWmAJwQWeCu18zQ97s_A?view= , a few concerns here:

benjaminhuo commented 2 years ago

Another point is we might need to add a callback in the function signature?

image

benjaminhuo commented 2 years ago

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:

Async functions:

Sync functions

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 image

@tpiperatgod @wanjunlei

benjaminhuo commented 2 years ago

aws lambda function:

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)

benjaminhuo commented 2 years ago

Proposal created for this : https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/202112_functions_framework_refactoring.md

benjaminhuo commented 2 years ago

Close this via https://github.com/OpenFunction/functions-framework-go/pull/22