I am trying to generate a UUID in Go in a specific pattern. The program that I am working on requires various uuids to be generated similar to an existing uuid string. So the program would read an existing uuid (whose format can change in the future) and generate a new uuid in the same format to replace the existing one.
I have used the "github.com/satori/go.uuid" package to generate an uuid. The sample code that I am using is below which I found online.
As multiple instances of this programs would be deployed in parallel, I would like to avoid collisions or duplication in the uuids generated.
package main
import (
"fmt"
"github.com/satori/go.uuid"
)
func main() {
// Creating UUID Version 4
// panic on error
u1 := uuid.Must(uuid.NewV4(), nil)
fmt.Printf("UUIDv4: %s
", u1)
// or error handling
u2:= uuid.NewV4()
fmt.Printf("UUIDv4: %s
", u2)
/* Formats needed:
2286664c688130096c9ce9008e4d97fb
6abb173a-b134-49f2-aa88-9dff5dab12a1 (This is obtained from the above code)
C8-3C-9C-64-61-70-62-B9-34-AC-9A-20-C9-EF-1D-6D
*/
}