Skip to content

Instantly share code, notes, and snippets.

@rdallman
Created October 20, 2017 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdallman/b3bb49795c43973997816d8fc0c517f7 to your computer and use it in GitHub Desktop.
Save rdallman/b3bb49795c43973997816d8fc0c517f7 to your computer and use it in GitHub Desktop.
go-fdk-ex-2
package main
import (
"context"
"encoding/json"
"fmt"
"io"
fdk "github.com/fnproject/fdk-go"
)
func main() {
fdk.Handle(fdk.HandlerFunc(myHandler))
}
func myHandler(ctx context.Context, in io.Reader, out io.Writer) {
var person struct {
Name string `json:"name"`
}
json.NewDecoder(in).Decode(&person)
if person.Name == "" {
person.Name = "world"
}
msg := struct {
Msg string `json:"msg"`
}{
Msg: fmt.Sprintf("Hello %s!\n", person.Name),
}
json.NewEncoder(out).Encode(&msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment