Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
495 B

package lib
import (
"github.com/hashicorp/go-uuid"
)
// UUIDCheckFunc should determine whether the given UUID is actually
// unique and allowed to be used
type UUIDCheckFunc func(string) (bool, error)
func GenerateUUID(checkFn UUIDCheckFunc) (string, error) {
for {
id, err := uuid.GenerateUUID()
if err != nil {
return "", err
}
if checkFn == nil {
return id, nil
}
if ok, err := checkFn(id); err != nil {
return "", err
} else if ok {
return id, nil
}
}
}