Skip to content

Conversation

tpiperatgod
Copy link
Member

In this pr, I adjusted functions-framework-go from only supporting one input to supporting multiple inputs, and adjusted the return value of the function from a specific code to a Return structure.

The main changes are reflected in the following places:

  1. OpenFunctionContext
type OpenFunctionContext struct {
-  Name      string             `json:"name"`
-  Version   string             `json:"version"`
-  RequestID string             `json:"requestID,omitempty"`
-  Input     Input              `json:"input,omitempty"`
-  Outputs   map[string]*Output `json:"outputs,omitempty"`
-  Runtime   Runtime            `json:"runtime"`
-  Port      string             `json:"port,omitempty"`
-  State     interface{}        `json:"state,omitempty"`
+  Name         string               `json:"name"`
+  Version      string               `json:"version"`
+  RequestID    string               `json:"requestID,omitempty"`
+  Inputs       map[string]*Input    `json:"inputs,omitempty"`
+  Outputs      map[string]*Output   `json:"outputs,omitempty"`
+  Runtime      Runtime              `json:"runtime"`
+  Port         string               `json:"port,omitempty"`
+  State        interface{}          `json:"state,omitempty"`
+  BindingEvent *common.BindingEvent `json:"bindingEvent,omitempty"`
+  TopicEvent   *common.TopicEvent   `json:"topicEvent,omitempty"`
}

Firstly, Input(Input) is changed to Inputs(map[string]*Input)
Also added BindingEvent(to store bindings events) and TopicEvent(to store topic events)

Maybe a function like GetData is needed to get the data from the specified input?

  1. SendTo function
- func (ctx *OpenFunctionContext) SendTo(data []byte, outputName string) error {
+ func (ctx *OpenFunctionContext) SendTo(data interface{}, outputName string) ([]byte, error) {

Modified the input data to interface{} type, SendTo will automatically wrap the incoming non-[]byte type data in json format automatically. Also modified the return value to add the return data.

  1. Function Return

A new Return structure has been added to handle the return of the function.

type Return struct {
  Code     ReturnCode        `json:"code"`
  Data     []byte            `json:"data,omitempty"`
  Metadata map[string]string `json:"metadata,omitempty"`
  Error    string            `json:"error,omitempty"`
}

Code indicates the return value of the function and currently supports: Success (200) for the success of the function and InternalError (500) for the exception of the function.

Data, Metadata, Error can be used to store the data, metadata, and error information that needs to be returned. I plan to add some hook configurations for handling function returns later in the evolution, and the return data here will be used by the processing module in the hook.

Signed-off-by: laminar fangtian@kubesphere.io

@tpiperatgod tpiperatgod linked an issue Sep 15, 2021 that may be closed by this pull request
Signed-off-by: laminar <fangtian@kubesphere.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need to support multiple input sources
2 participants