func CloudEvent(ctx context.Context, ce cloudevents.Event) error {
	e, err := json.Marshal(ce)
	if err != nil {
		return fmt.Errorf("marshalling cloud event: %v", err)
	}
	if err := ioutil.WriteFile(outputFile, e, 0644); err != nil {
		return fmt.Errorf("writing file: %v", err)
	}
	return nil
}
CloudEvent is a cloud event function that dumps the event to JSON and calls the validator script
on the result.
package function
import (
	"context"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"cloud.google.com/go/functions/metadata"
	_ "github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
	cloudevents "github.com/cloudevents/sdk-go/v2"
)
const (
	outputFile = "function_output.json"
)
func HTTP(w http.ResponseWriter, r *http.Request) {
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	if err := ioutil.WriteFile(outputFile, body, 0644); err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
}
func Event(ctx context.Context, data interface{}) error {
	m, err := metadata.FromContext(ctx)
	if err != nil {
		return fmt.Errorf("getting context metadata: %v", err)
	}
	event := struct {
		Data    interface{}        `json:"data"`
		Context *metadata.Metadata `json:"context"`
	}{
		Data:    data,
		Context: m,
	}
	e, err := json.Marshal(event)
	if err != nil {
		return fmt.Errorf("marshalling event: %v", err)
	}
	log.Printf("writing %v, %s to file", event, string(e))
	return ioutil.WriteFile(outputFile, e, 0644)
}