Skip to content

Instantly share code, notes, and snippets.

@Rukenshia
Last active April 20, 2018 18:21
Show Gist options
  • Save Rukenshia/8e8dbf95a36f0928d77e01e41387651f to your computer and use it in GitHub Desktop.
Save Rukenshia/8e8dbf95a36f0928d77e01e41387651f to your computer and use it in GitHub Desktop.
Vault library basic usage
package main
import (
"github.com/hashicorp/vault/api"
)
func main() {
// Create the client
cfg := api.DefaultConfig()
cfg.Address = "http://myVaultAddress:8200"
client, err := api.NewClient(cfg)
if err != nil {
log.Fatal(err)
}
client.SetToken("abcdefg-mytoken")
// Example: Write
_, err = client.Logical().Write("secrets/my-secret", map[string]interface{}{
"value": "hello there",
})
if err != nil {
log.Fatal(err)
}
// Example: Read
mySecret, err := client.Logical().Read("secrets/my-secret")
if err != nil {
log.Fatal(err)
}
log.Printf("My Secret Value is %v", mySecret.Data["value"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment