mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
30 lines
469 B
Go
30 lines
469 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
|
|
fdk "github.com/fnproject/fdk-go"
|
|
)
|
|
|
|
func main() {
|
|
fdk.Handle(fdk.HandlerFunc(myHandler))
|
|
}
|
|
|
|
type Person struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func myHandler(ctx context.Context, in io.Reader, out io.Writer) {
|
|
p := &Person{Name: "World"}
|
|
json.NewDecoder(in).Decode(p)
|
|
msg := struct {
|
|
Msg string `json:"message"`
|
|
}{
|
|
Msg: fmt.Sprintf("Hello %s", p.Name),
|
|
}
|
|
json.NewEncoder(out).Encode(&msg)
|
|
}
|