github.com/pachyderm/pachyderm@v1.13.4/src/server/pkg/uuid/uuid.go (about)

     1  package uuid
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"strings"
     7  	"time"
     8  
     9  	"github.com/pachyderm/pachyderm/src/server/pkg/backoff"
    10  	uuid "github.com/satori/go.uuid"
    11  )
    12  
    13  // New returns a new uuid.
    14  func New() string {
    15  	var result string
    16  	backoff.RetryNotify(func() error {
    17  		uuid := uuid.NewV4()
    18  		result = uuid.String()
    19  		return nil
    20  	}, backoff.NewInfiniteBackOff(), func(err error, d time.Duration) error {
    21  		fmt.Printf("error from uuid.NewV4: %v", err)
    22  		return nil
    23  	})
    24  	return result
    25  }
    26  
    27  // NewWithoutDashes returns a new uuid without no "-".
    28  func NewWithoutDashes() string {
    29  	return strings.Replace(New(), "-", "", -1)
    30  }
    31  
    32  // NewWithoutUnderscores returns a new uuid without no "_".
    33  func NewWithoutUnderscores() string {
    34  	return strings.Replace(New(), "_", "", -1)
    35  }
    36  
    37  // IsUUIDWithoutDashes checks whether a string is a UUID without dashes
    38  func IsUUIDWithoutDashes(s string) bool {
    39  	return uuidWithoutDashesRegexp.MatchString(s)
    40  }
    41  
    42  // Because we use UUIDv4, the 13th character is a '4'.
    43  // Moreover, a UUID can only contain "hexadecimal" characters,
    44  // lowercase here.
    45  var uuidWithoutDashesRegexp = regexp.MustCompile("[0-9a-f]{12}4[0-9a-f]{19}")