I'm trying to get at the underlying data for this mess. It's a GKE-specific PubSub message and I don't know what the underlying JSON looks like. There's also an attributes key in the json and that's what I'm most interested in. Is there a way I can just dump the incoming json so I can see what it looks like?
// Package p contains a Pub/Sub Cloud Function.
package p
import (
"context"
"log"
)
// PubSubMessage is the payload of a Pub/Sub event. Please refer to the docs for
// additional information regarding Pub/Sub events.
type PubSubMessage struct {
Data []byte `json:"data"`
}
// HelloPubSub consumes a Pub/Sub message.
func HelloPubSub(ctx context.Context, m PubSubMessage) error {
log.Println(string(m.Data))
return nil
}
CodePudding user response:
json.NewEncoder(os.Stdout).Encode(&m)
should encode as json and write to stdout