Created
October 20, 2017 23:21
-
-
Save rdallman/b3bb49795c43973997816d8fc0c517f7 to your computer and use it in GitHub Desktop.
go-fdk-ex-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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