Go - Secret.Version()

Returns a reference to a known version of a secret.

import (
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
if err != nil {
return
}
version := secret.Version("the-version-id")
nitric.Run()
}

Parameters

  • Name
    version
    Required
    Required
    Type
    string
    Description

    The version ID. This value is returned from secret.Put().

Examples

Return a reference to a known secret version

import (
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
if err != nil {
return
}
version := secret.Version("the-version-id")
nitric.Run()
}

Access the value of a known secret version

import (
"context"
"fmt"
"github.com/nitrictech/go-sdk/nitric"
)
func main() {
secret, err := nitric.NewSecret("secret-name").With(nitric.SecretAccessing)
if err != nil {
return
}
version, err := secret.Version("the-version-id").Access(context.TODO())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(version.AsString())
nitric.Run()
}

See also

Last updated on Dec 24, 2024