github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/singleton/uniqid/uniqid.go (about)

     1  package uniqid
     2  
     3  import (
     4  	"sync"
     5  
     6  	uid "github.com/ActiveState/cli/internal/uniqid"
     7  )
     8  
     9  var (
    10  	mu  sync.Mutex
    11  	def *uid.UniqID
    12  )
    13  
    14  // Text returns the stored or new unique id as a string.
    15  func Text() string {
    16  	mu.Lock()
    17  	defer mu.Unlock()
    18  
    19  	if def == nil {
    20  		id, err := uid.New(uid.InHome)
    21  		if err != nil {
    22  			// log error
    23  			return ""
    24  		}
    25  
    26  		def = id
    27  	}
    28  
    29  	return def.String()
    30  }