To start using this SDK, just:
go get github.com/videsk/doppler-go-sdk
Using the method GetSecrets
you will retrieve all secrets in once.
package main
import (
"log"
"github.com/videsk/doppler-go-sdk"
)
func main() {
dopplerClient, err := doppler.NewDoppler("projectName", "secretKey", "environment")
if err != nil {
log.Fatalf("Error with Doppler instance: %v", err)
}
dopplerClient.SetHTTPClient(http.DefaultClient)
secrets, err := dopplerClient.GetSecrets()
if err != nil {
log.Fatalf("Error getting the secrets: %v", err)
}
for key, value := range secrets {
log.Printf("Error getting: %s, Value: %s\n", key, value)
}
// The rest of the code ...
}
Using the method GetOne
you will retrieve one secret in once, but calling getSecrets
. Which is not efficient if you need get more than one at the same time.
package main
import (
"log"
"github.com/videsk/doppler-go-sdk"
)
func main() {
dopplerClient, err := doppler.NewDoppler("projectName", "secretKey", "environment")
if err != nil {
log.Fatalf("Error with Doppler instance: %v", err)
}
dopplerClient.SetHTTPClient(http.DefaultClient)
secretName := "my_secret_name"
secretValue, err := dopplerClient.GetOne(secretName)
if err != nil {
log.Fatalf("Error getting the secret %s: %v", secretName, err)
}
log.Printf("The secret value is '%s': %s\n", secretName, secretValue)
// The rest of the code ...
}
In case you want retrieve multiples values you can just:
secrets, err := dopplerClient.GetSecrets()
if err != nil {
log.Fatalf("Error getting the secrets: %v", err)
}
mySecret1 := secrets["my_secret_name"]
mySecret2 := secrets["my_super_secret"]