mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Fixes async payload passing for #68.
This commit is contained in:
6
examples/tutorial/async/go/.gitignore
vendored
Normal file
6
examples/tutorial/async/go/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
vendor/
|
||||
/go
|
||||
/app
|
||||
/__uberscript__
|
||||
|
||||
func.yaml
|
||||
28
examples/tutorial/async/go/README.md
Normal file
28
examples/tutorial/async/go/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Aynchronous Function Example
|
||||
|
||||
This is an example of an [asynchronous function](/docs/async.md).
|
||||
|
||||
### First, run the following commands:
|
||||
|
||||
```sh
|
||||
# Initialize your function creating a func.yaml file
|
||||
fn init --type async <DOCKERHUB_USERNAME>/hello-go-async
|
||||
|
||||
# Test your function. This will run inside a container exactly how it will on the server
|
||||
fn run
|
||||
|
||||
# Now try with an input
|
||||
cat sample.payload.json | fn run
|
||||
|
||||
# Deploy your functions to the Oracle Functions server (default localhost:8080)
|
||||
# This will create a route to your function as well
|
||||
fn deploy myapp
|
||||
```
|
||||
|
||||
### Now call your function:
|
||||
|
||||
```sh
|
||||
cat payload.json | fn call myapp hello-go-async
|
||||
```
|
||||
|
||||
That's it!
|
||||
27
examples/tutorial/async/go/func.go
Normal file
27
examples/tutorial/async/go/func.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// b, err := ioutil.ReadAll(os.Stdin)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// fmt.Printf("BODY!!! %s", string(b))
|
||||
|
||||
p := &Person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
fmt.Printf("Hello %v!\n", p.Name)
|
||||
|
||||
log.Println("---> stderr goes to the server logs.")
|
||||
}
|
||||
3
examples/tutorial/async/go/sample.payload.json
Normal file
3
examples/tutorial/async/go/sample.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
Reference in New Issue
Block a user