

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Ottieni un valore segreto di Secrets Manager utilizzando Go AWS SDK
<a name="retrieving-secrets-go-sdk"></a>

Nelle applicazioni, puoi recuperare i tuoi segreti chiamando `GetSecretValue` o `BatchGetSecretValue` in uno qualsiasi dei. AWS SDKs Tuttavia, ti consigliamo di memorizzare nella cache i valori del segreto utilizzando la caching lato client. Memorizzare i segreti nella cache migliora la velocità e riduce i costi.

Per le applicazioni Go, utilizza il [componente di caching basato su Go di Secrets Manager](retrieving-secrets_cache-go.md) o chiama direttamente l'SDK con [https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#SecretsManager.GetSecretValue](https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#SecretsManager.GetSecretValue) o [https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#SecretsManager.BatchGetSecretValue](https://docs.aws.amazon.com/sdk-for-go/api/service/secretsmanager/#SecretsManager.BatchGetSecretValue).

I seguenti esempi di codice mostrano come recuperare un valore segreto di Gestione dei segreti.

**Autorizzazioni richieste:**`secretsmanager:GetSecretValue`

```
  // Use this code snippet in your app.
  // If you need more information about configurations or implementing the sample code, visit the AWS docs:   
  // https://aws.github.io/aws-sdk-go-v2/docs/getting-started/
  
  import (
    "context"
    "log"
  
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
  )
  
  func main() {
    secretName := "<<{{MySecretName}}>>"
    region := "<<{{MyRegionName}}>>"
  
    config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
    if err != nil {
      log.Fatal(err)
    }
  
    // Create Secrets Manager client
    svc := secretsmanager.NewFromConfig(config)
  
    input := &secretsmanager.GetSecretValueInput{
      SecretId:     aws.String(secretName),
      VersionStage: aws.String("AWSCURRENT"), // VersionStage defaults to AWSCURRENT if unspecified
    }
  
    result, err := svc.GetSecretValue(context.TODO(), input)
    if err != nil {
      // For a list of exceptions thrown, see
      // https://<<{{DocsDomain}}>>/secretsmanager/latest/apireference/API_GetSecretValue.html
      log.Fatal(err.Error())
    }
  
    // Decrypts secret using the associated KMS key.
    var secretString string = *result.SecretString
  
    // Your code goes here.
  }
```