示例#1
0
文件: pubsub.go 项目: Tecsisa/dex
// This example demonstrates calling the Cloud Pub/Sub API. As of 20
// Aug 2014, the Cloud Pub/Sub API is only available if you're
// whitelisted. If you're interested in using it, please apply for the
// Limited Preview program at the following form:
// http://goo.gl/Wql9HL
//
// Also, before running this example, be sure to enable Cloud Pub/Sub
// service on your project in Developer Console at:
// https://console.developers.google.com/
//
// It has 8 subcommands as follows:
//
// PROJ list_topics
// PROJ create_topic TOPIC
// PROJ delete_topic TOPIC
// PROJ list_subscriptions
// PROJ create_subscription SUBSCRIPTION LINKED_TOPIC
// PROJ delete_subscription SUBSCRIPTION
// PROJ connect_irc TOPIC SERVER CHANNEL
// PROJ pull_messages SUBSCRIPTION
//
// You can use either of your alphanumerical or numerial Cloud Project
// ID for PROJ. You can choose any names for TOPIC and SUBSCRIPTION as
// long as they follow the naming rule described at:
// https://developers.google.com/pubsub/overview#names
//
// You can list/create/delete topics/subscriptions by self-explanatory
// subcommands, as well as connect to an IRC channel and publish
// messages from the IRC channel to a specified Cloud Pub/Sub topic by
// the "connect_irc" subcommand, or continuously pull messages from a
// specified Cloud Pub/Sub subscription and display the data by the
// "pull_messages" subcommand.
func pubsubMain(client *http.Client, argv []string) {
	checkArgs(argv, 2)
	service, _ := pubsub.New(client)
	m := map[string]func(service *pubsub.Service, argv []string){
		"list_topics":         listTopics,
		"list_subscriptions":  listSubscriptions,
		"create_topic":        createTopic,
		"delete_topic":        deleteTopic,
		"create_subscription": createSubscription,
		"delete_subscription": deleteSubscription,
		"connect_irc":         connectIRC,
		"pull_messages":       pullMessages,
	}
	f, ok := m[argv[1]]
	if !ok {
		pubsubUsage()
		os.Exit(2)
	}
	f(service, argv)
}
示例#2
0
文件: pubsub.go 项目: hanscj1/mantle
func rawService(ctx context.Context) *raw.Service {
	return internal.Service(ctx, "pubsub", func(hc *http.Client) interface{} {
		svc, _ := raw.New(hc)
		return svc
	}).(*raw.Service)
}