mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Updated docs on configuration and required env vars. (#285)
* Updated docs on configuration and required env vars. * minor
This commit is contained in:
6
examples/inputs/.gitignore
vendored
Normal file
6
examples/inputs/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
vendor/
|
||||
/go
|
||||
/app
|
||||
/__uberscript__
|
||||
|
||||
func.yaml
|
||||
15
examples/inputs/README.md
Normal file
15
examples/inputs/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Tutorial 1: Go Function w/ Input (3 minutes)
|
||||
|
||||
Example for putting required vars into the func.yaml file.
|
||||
|
||||
Try running the following:
|
||||
|
||||
```sh
|
||||
fn run
|
||||
# > ERROR: required env var SECRET_1 not found, please set either set it in your environment or pass in `-e SECRET_1=X` flag.
|
||||
SECRET_1=YOOO fn run
|
||||
# > info: optional env var SECRET_2 not found.
|
||||
# > {"SECRET_1":"YOOO","SECRET_2":"","message":"Hello World"}
|
||||
SECRET_1=YOOO SECRET_2=DAWG fn run
|
||||
# > {"SECRET_1":"YOOO","SECRET_2":"DAWG","message":"Hello World"}
|
||||
```
|
||||
21
examples/inputs/func.go
Normal file
21
examples/inputs/func.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
mapD := map[string]string{"message": fmt.Sprintf("Hello %s", p.Name)}
|
||||
mapD["SECRET_1"] = os.Getenv("SECRET_1")
|
||||
mapD["SECRET_2"] = os.Getenv("SECRET_2")
|
||||
mapB, _ := json.Marshal(mapD)
|
||||
fmt.Println(string(mapB))
|
||||
}
|
||||
3
examples/inputs/sample.payload.json
Normal file
3
examples/inputs/sample.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
26
examples/inputs/test.json
Normal file
26
examples/inputs/test.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"tests": [
|
||||
{
|
||||
"input": {
|
||||
"body": {
|
||||
"name": "Johnny"
|
||||
}
|
||||
},
|
||||
"output": {
|
||||
"body": {
|
||||
"message": "Hello Johnny"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"body": ""
|
||||
},
|
||||
"output": {
|
||||
"body": {
|
||||
"message": "Hello World"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user