Elimina processore (v1)

Elimina un processore Document AI esistente.

Esempio di codice

Go

Per saperne di più, consulta la documentazione di riferimento dell'API Document AI Go.

Per eseguire l'autenticazione in Document AI, configura le Credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.


import (
	"context"
	"fmt"
	"io"

	documentai "cloud.google.com/go/documentai/apiv1beta3"
	"cloud.google.com/go/documentai/apiv1beta3/documentaipb"
	"google.golang.org/api/option"
)

// deleteProcessor deletes an existing Document AI processor.
func deleteProcessor(ctx context.Context, w io.Writer, projectID string, locationID string, processorID string) error {
	name := fmt.Sprintf("projects/%s/locations/%s/processors/%s", projectID, locationID, processorID)

	endpoint := fmt.Sprintf("%s-documentai.googleapis.com:443", locationID)
	client, err := documentai.NewDocumentProcessorClient(ctx, option.WithEndpoint(endpoint))
	if err != nil {
		return fmt.Errorf("NewDocumentProcessorClient: %w", err)
	}
	defer client.Close()

	req := &documentaipb.DeleteProcessorRequest{
		Name: name,
	}

	op, err := client.DeleteProcessor(ctx, req)
	if err != nil {
		return fmt.Errorf("DeleteProcessor: %w", err)
	}

	// DeleteProcessor is a long-running operation; wait for completion.
	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("op.Wait: %w", err)
	}

	fmt.Fprintf(w, "Processor deleted: %s\n", name)
	return nil
}

Java

Per saperne di più, consulta la documentazione di riferimento dell'API Document AI Java.

Per eseguire l'autenticazione in Document AI, configura le Credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.ProcessorName;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteProcessor {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project_id";
    String locationId = "example-location_id";
    String processorId = "example-processor_id";
    deleteProcessor(projectId, locationId, processorId);
  }

  public static void deleteProcessor(String projectId, String locationId, String processorId)
      throws Exception {
    try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create()) {
      String name = ProcessorName.of(projectId, locationId, processorId).toString();

      // DeleteProcessor is a long-running operation.
      OperationFuture<Empty, DeleteProcessorMetadata> operation = client.deleteProcessorAsync(name);
      operation.get(5, TimeUnit.MINUTES);

      System.out.printf("Processor deleted successfully: %s%n", name);
    }
  }
}

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .