Flamenco/internal/uuid/uuid.go
Sybren A. Stüvel f77b11d85e Manager: add a small wrapper around Google's UUID library
Add a small wrapper around github.com/google/uuid. That way it's clearer
which functionality is used by Flamenco, doesn't link most of the code to
any specific UUID library, and allows a bit of customisation.

The only customisation now is that Flamenco is a bit stricter in the
formats it accepts; only the `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` is
accepted. This makes things a little bit stricter, with the advantage
that we don't need to do any normalisation of received UUID strings.
2022-05-20 15:35:51 +02:00

26 lines
571 B
Go

// uuid is a thin wrapper around github.com/google/uuid.
package uuid
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"github.com/google/uuid"
)
// New generates a random UUID.
func New() string {
return uuid.New().String()
}
// IsValid returns true when the string can be parsed as UUID.
func IsValid(value string) bool {
// uuid.Parse() accepts a few different notations for UUIDs, but Flamenco only
// works with the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
if len(value) != 36 {
return false
}
_, err := uuid.Parse(value)
return err == nil
}