Skip to content

Commit

Permalink
feat: add Golang context
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jun 10, 2021
1 parent 0bab3ae commit a9e83fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/104-go1-16-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def handler(msg):
(kafka('input-topic')
.handler('main', code="""package main
func Handler(m []byte) ([]byte, error) {
import "context"
func Handler(ctx context.Context, m []byte) ([]byte, error) {
return []byte("hi " + string(m)), nil
}""", runtime='go1-16')
.log()
Expand Down
4 changes: 3 additions & 1 deletion examples/104-go1-16-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ spec:
code: |-
package main
func Handler(m []byte) ([]byte, error) {
import "context"
func Handler(ctx context.Context, m []byte) ([]byte, error) {
return []byte("hi " + string(m)), nil
}
runtime: go1-16
Expand Down
4 changes: 3 additions & 1 deletion runtimes/go1-16/handler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

func Handler(m []byte) ([]byte, error) {
import "context"

func Handler(background context.Context, m []byte) ([]byte, error) {
return []byte("hi " + string(m)), nil
}
3 changes: 2 additions & 1 deletion runtimes/go1-16/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"io/ioutil"
"net/http"
)
Expand All @@ -15,7 +16,7 @@ func main() {
if in, err := ioutil.ReadAll(r.Body); err != nil {
return nil, err
} else {
return Handler(in)
return Handler(context.Background(), in)
}
}()
if err != nil {
Expand Down

0 comments on commit a9e83fa

Please sign in to comment.