Todos os produtos
Search
Central de documentação

Object Storage Service:Excluir tags de objeto (Go SDK V2)

Última atualização: Jul 03, 2026

Este tópico descreve como excluir as tags de um objeto com o OSS SDK for Go V2.

Observações de uso

  • O código de exemplo deste tópico usa o ID da região cn-hangzhou, referente à região China (Hangzhou). Por padrão, o acesso aos recursos em um bucket ocorre via endpoint público. Para acessar os recursos do bucket por meio de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para mais informações sobre as regiões e endpoints compatíveis com o OSS, consulte Regiões e endpoints do OSS.

  • Neste tópico, as credenciais de acesso são obtidas de variáveis de ambiente. Para saber mais sobre a configuração de credenciais de acesso, consulte Configurar credenciais de acesso.

  • A exclusão de tags de objeto exige a permissão oss:DeleteObjectTagging. Para mais detalhes, consulte Conceder política personalizada a usuários RAM.

Nota
  • A marcação de objetos usa pares chave-valor para identificação. Para mais informações sobre esse recurso, consulte Marcação de objetos no Guia do Desenvolvedor do OSS.

  • Para obter mais detalhes sobre como excluir tags de um objeto, consulte DeleteObjectTagging.

Código de exemplo

O código a seguir mostra como excluir as tags de um objeto em um bucket.

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

// Define global variables.
var (
	region     string // Region in which the bucket is located.
	bucketName string // Name of the bucket.
	objectName string // Name of the object.
)

// Specify the init function used to initialize command line parameters.
func init() {
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	flag.StringVar(&objectName, "object", "", "The name of the object.")
}

func main() {
	// Parse command line parameters.
	flag.Parse()

	// Check whether the name of the bucket is specified.
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	// Check whether the region is specified.
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	// Check whether the name of the object is specified.
	if len(objectName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, object name required")
	}

	// Load the default configurations and specify the credential provider and region.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region)

	// Create an OSS client.
	client := oss.NewClient(cfg)

	// Create a request to delete the tags of the object.
	request := &oss.DeleteObjectTaggingRequest{
		Bucket: oss.Ptr(bucketName), // Name of the bucket.
		Key:    oss.Ptr(objectName), // Name of the object.
	}

	// Delete the tags and process the results.
	result, err := client.DeleteObjectTagging(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to delete object tagging %v", err)
	}

	// Display the result.
	log.Printf("delete object tagging result:%#v\n", result)
}

Referências

  • Para obter o código de exemplo completo de exclusão de tags de objeto, visite o repositório no GitHub.

  • Para mais informações sobre a operação de API usada para excluir tags de objeto, consulte DeleteObjectTagging.