45 lines
793 B
Go
45 lines
793 B
Go
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))
|
|
}
|