Created
April 24, 2020 20:27
-
-
Save vtatai/2c9f33bd02aa673c1469e0ce8dcbbf12 to your computer and use it in GitHub Desktop.
Sample golang lambda pub/sub consumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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