Excluir processador (v1)

Excluir um processador da Document AI.

Exemplo de código

Go

Para mais informações, consulte a documentação de referência da API Document AI Go.

Para autenticar na Document AI, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.


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

Para mais informações, consulte a documentação de referência da API Document AI Java.

Para autenticar na Document AI, configure o Application Default Credentials. Para mais informações, consulte Configurar a autenticação para um ambiente de desenvolvimento local.

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);
    }
  }
}

A seguir

Para pesquisar e filtrar exemplos de código de outros Google Cloud produtos, consulte a Google Cloud pesquisa de exemplos de código.