Skip to content

Instantly share code, notes, and snippets.

@vtatai
Created April 24, 2020 20:27
Show Gist options
  • Save vtatai/2c9f33bd02aa673c1469e0ce8dcbbf12 to your computer and use it in GitHub Desktop.
Save vtatai/2c9f33bd02aa673c1469e0ce8dcbbf12 to your computer and use it in GitHub Desktop.
Sample golang lambda pub/sub consumer
// Package helloworld provides a set of Cloud Functions samples.
package helloworld
import (
"context"
"log"
)
// PubSubMessage is the payload of a Pub/Sub event.
type PubSubMessage struct {
Data []byte `json:"data"`
}
// HelloPubSub consumes a Pub/Sub message.
func HelloPubSub(ctx context.Context, m PubSubMessage) error {
name := string(m.Data)
if name == "" {
name = "World"
}
log.Printf("Hello, %s!", name)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment