コード例 #1
0
ファイル: registry.go プロジェクト: nildev/account
// 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
ファイル: registry.go プロジェクト: nildev/account
// 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
}