קבלת אינדקס אדמין

קבלת אינדקס אדמין

דוגמת קוד

C#

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode C# API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


using Google.Cloud.Datastore.Admin.V1;
using System;
using Index = Google.Cloud.Datastore.Admin.V1.Index;

public class GetIndexSample
{
    public Index GetIndex(
        string projectId = "your-project-id",
        string indexId = "your-index-id")
    {
        // Create client
        DatastoreAdminClient datastoreAdminClient = DatastoreAdminClient.Create();

        // Initialize request argument(s)
        GetIndexRequest getIndexRequest = new GetIndexRequest
        {
            ProjectId = projectId,
            IndexId = indexId
        };

        Index index = datastoreAdminClient.GetIndex(getIndexRequest);

        Console.WriteLine($"Index Id: {index.IndexId}");
        Console.WriteLine($"Kind: {index.Kind}");
        Console.WriteLine("Properties:");
        foreach (var property in index.Properties)
        {
            Console.WriteLine($"Property: {property.Name}");
            Console.WriteLine($"Direction: {property.Direction}");
        }
        return index;
    }
}

Go

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Go API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	admin "cloud.google.com/go/datastore/admin/apiv1"
	"cloud.google.com/go/datastore/admin/apiv1/adminpb"
)

// indexGet gets an index.
func indexGet(w io.Writer, projectID, indexID string) (*adminpb.Index, error) {
	// projectID := "my-project-id"
	// indexID := "my-index"
	ctx := context.Background()
	client, err := admin.NewDatastoreAdminClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("admin.NewDatastoreAdminClient: %w", err)
	}
	defer client.Close()

	req := &adminpb.GetIndexRequest{
		ProjectId: projectID,
		IndexId:   indexID,
	}
	index, err := client.GetIndex(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("client.GetIndex: %w", err)
	}

	fmt.Fprintf(w, "Got index: %v\n", index.IndexId)
	return index, nil
}

Python

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Python API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

def get_index(project_id, index_id):
    """Gets an index."""
    # project_id := "my-project-id"
    # index_id := "my-index"
    client = DatastoreAdminClient()
    index = client.get_index({"project_id": project_id, "index_id": index_id})

    print("Got index: %v\n", index.index_id)
    return index

Ruby

מידע על התקנת ספריית הלקוח למצב Datastore ושימוש בה מופיע במאמר ספריות הלקוח של מצב Datastore. מידע נוסף מופיע במאמרי העזרה של Datastore mode Ruby API.

כדי לבצע אימות במצב Datastore, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

# project_id = "project-id"
# index_id = "my-index"
index = client.get_index project_id: project_id, index_id: index_id
puts "Got index: #{index.index_id}"

המאמרים הבאים

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , אפשר להיעזר בGoogle Cloud דפדפן לדוגמה.