@@ -58,7 +58,16 @@ const (
5858type Runtime string
5959type ResourceType string
6060
61+ type NativeContext interface {
62+ // GetNativeContext returns the Go native context object.
63+ GetNativeContext () context.Context
64+
65+ // SetNativeContext set the Go native context object.
66+ SetNativeContext (context.Context )
67+ }
68+
6169type RuntimeContext interface {
70+ NativeContext
6271
6372 // GetName returns the function's name.
6473 GetName () string
@@ -69,9 +78,6 @@ type RuntimeContext interface {
6978 // GetContext returns the pointer of raw OpenFunction FunctionContext object.
7079 GetContext () * FunctionContext
7180
72- // GetNativeContext returns the Go native context object.
73- GetNativeContext () context.Context
74-
7581 // GetOut returns the pointer of raw OpenFunction FunctionOut object.
7682 GetOut () Out
7783
@@ -150,6 +156,7 @@ type RuntimeContext interface {
150156}
151157
152158type Context interface {
159+ NativeContext
153160
154161 // Send provides the ability to allow the user to send data to a specified output target.
155162 Send (outputName string , data []byte ) ([]byte , error )
@@ -466,6 +473,10 @@ func (ctx *FunctionContext) GetNativeContext() context.Context {
466473 return ctx .Ctx
467474}
468475
476+ func (ctx * FunctionContext ) SetNativeContext (c context.Context ) {
477+ ctx .Ctx = c
478+ }
479+
469480func (ctx * FunctionContext ) SetSyncRequest (w http.ResponseWriter , r * http.Request ) {
470481 ctx .mu .Lock ()
471482 defer ctx .mu .Unlock ()
@@ -805,6 +816,9 @@ func ConvertUserDataToBytes(data interface{}) []byte {
805816 if d , ok := data .([]byte ); ok {
806817 return d
807818 }
819+ if d , ok := data .(string ); ok {
820+ return []byte (d )
821+ }
808822 if d , err := json .Marshal (data ); err != nil {
809823 return nil
810824 } else {
0 commit comments