Files
threshold/internal/db/id.go
T
Louis Ruch ec0020de90 Refactor host_repo -> domain errors (#786)
* Refactor domain errors: New -> E, create helper New and Wrap
* Update host repo to use domain errors
2020-12-09 10:11:38 -08:00

30 lines
680 B
Go

package db
import (
"fmt"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/vault/sdk/helper/base62"
)
func NewPrivateId(prefix string) (string, error) {
return newId(prefix)
}
// NewPublicId creates a new public id with the prefix
func NewPublicId(prefix string) (string, error) {
return newId(prefix)
}
func newId(prefix string) (string, error) {
const op = "db.newId"
if prefix == "" {
return "", errors.New(errors.InvalidParameter, op, "missing prefix")
}
publicId, err := base62.Random(10)
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("unable to generate id"))
}
return fmt.Sprintf("%s_%s", prefix, publicId), nil
}