Files
threshold/internal/observability/event/id.go
T

25 lines
619 B
Go
Raw Normal View History

2021-06-06 07:57:24 -04:00
package event
import (
2021-06-22 16:23:27 -05:00
"fmt"
2021-06-23 12:26:09 -05:00
"github.com/hashicorp/vault/sdk/helper/base62"
2021-06-06 07:57:24 -04:00
)
2021-06-23 12:26:09 -05:00
// This modified newId has been done to stop a circular
// dependency with the errors package that is caused by importing
// boundary/internal/db
2021-06-06 07:57:24 -04:00
func newId(prefix string) (string, error) {
const op = "event.newId"
2021-06-23 12:26:09 -05:00
if prefix == "" {
return "", fmt.Errorf("%s: missing prefix: %w", op, ErrInvalidParameter)
}
var publicId string
var err error
publicId, err = base62.Random(10)
2021-06-06 07:57:24 -04:00
if err != nil {
2021-06-23 12:26:09 -05:00
return "", fmt.Errorf("%s: unable to generate id %v: %w", op, err, ErrIo)
2021-06-06 07:57:24 -04:00
}
2021-06-23 12:26:09 -05:00
return fmt.Sprintf("%s_%s", prefix, publicId), nil
2021-06-06 07:57:24 -04:00
}