示例#1
0
// CreateGooglePubSubClient returns client communicate with google Pub/Sub service
func CreateGooglePubSubClient() (*pubsub.Client, error) {
	envValue := os.Getenv(NDGooglePubSubURL)
	if envValue != "" {
		googlePubSubURL = envValue
	}

	envValue = os.Getenv(NDGoogleProjectID)
	if envValue != "" {
		googleProjectID = envValue
	}

	ctx := cloud.NewContext(googleProjectID, http.DefaultClient)
	o := []cloud.ClientOption{
		cloud.WithBaseHTTP(http.DefaultClient),
		cloud.WithEndpoint(googleDatastoreURL),
	}
	client, _ := pubsub.NewClient(ctx, googleProjectID, o...)
	return client, nil
}
示例#2
0
// CreateGoogleDatastoreClient create client to communicate to google Datastore service
func CreateGoogleDatastoreClient() (*datastore.Client, error) {
	envValue := os.Getenv(NDGoogleDatastoreURL)
	if envValue != "" {
		googleDatastoreURL = envValue
	}

	envValue = os.Getenv(NDGoogleProjectID)
	if envValue != "" {
		googleProjectID = envValue
	}

	ctx := cloud.NewContext(googleProjectID, http.DefaultClient)
	o := []cloud.ClientOption{
		cloud.WithBaseHTTP(http.DefaultClient),
		cloud.WithEndpoint(googleDatastoreURL),
	}
	client, err := datastore.NewClient(ctx, googleProjectID, o...)
	if err != nil {
		return nil, err
	}

	return client, nil
}