Faas semi worfking
This commit is contained in:
44
faas/examples/hello-world/main.go
Normal file
44
faas/examples/hello-world/main.go
Normal file
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Read input from environment variable
|
||||
input := os.Getenv("FUNCTION_INPUT")
|
||||
if input == "" {
|
||||
input = "{}"
|
||||
}
|
||||
|
||||
// Parse input
|
||||
var inputData map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(input), &inputData); err != nil {
|
||||
fmt.Printf("Error parsing input: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Process the input and generate output
|
||||
name, ok := inputData["name"].(string)
|
||||
if !ok {
|
||||
name = "World"
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("Hello, %s!", name)
|
||||
|
||||
// Output result as JSON
|
||||
result := map[string]interface{}{
|
||||
"message": message,
|
||||
"input": inputData,
|
||||
}
|
||||
|
||||
output, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling output: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
Reference in New Issue
Block a user