github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/pkg/helper/uuid.go (about)

     1  package helper
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  
     7  	uuid "github.com/satori/go.uuid"
     8  )
     9  
    10  func GenerateUuid(format string) (ret string) {
    11  	ret = uuid.NewV4().String()
    12  	sep := ""
    13  
    14  	regx := regexp.MustCompile(`uuid\(\s*(\S+)\s*\)`)
    15  	arr := regx.FindStringSubmatch(format)
    16  	if len(arr) > 1 {
    17  		sep = strings.Trim(arr[1], "'")
    18  	}
    19  	ret = strings.ReplaceAll(ret, "-", sep)
    20  
    21  	return
    22  }