github.com/tickstep/library-go@v0.1.1/ids/ids.go (about) 1 package ids 2 3 import ( 4 "fmt" 5 "github.com/denisbrodbeck/machineid" 6 "strings" 7 ) 8 9 const ( 10 DefaultUniqueId = "11884a11d126t51b74a1f99b91da91814c56a588fe6bf11f9224600e3a400fcc" 11 ) 12 13 func GetUniqueId(appId string, size int) string { 14 uid := DefaultUniqueId 15 16 var ( 17 id = "" 18 err = fmt.Errorf("") 19 ) 20 21 if appId == "" { 22 id, err = machineid.ID() 23 if err == nil { 24 uid = strings.ReplaceAll(id, "-", "") 25 } 26 } else { 27 id, err = machineid.ProtectedID("update-service-go") 28 if err == nil { 29 uid = id 30 } 31 } 32 33 if size > 0 && size < len(uid) { 34 return uid[:size] 35 } 36 return uid 37 }