This ia a library containing UUID generation and validation used in UPP's Golang services.
-
Generating an UUID based on another UUID: methods in deriveUUID.go
-
Generating an UUID from an random string (V3 version, i.e. using MD5 hashing): methods in generateV3UUID.go
-
Generating an UUID from an URL (V5 version, i.e. using SHA1 hashing): methods in generateV5UUID.go
-
Validating an UUID: methods in uuidValidation.go
Note: this library also contains methods that replicate java.util.UUID class (in uuid.go), for cases where it's already in use.
-
Import the library (in your code):
import ( uuidutils "github.com/Financial-Times/uuid-utils-go" )
-
Vendor it (e.g. with govendor):
govendor fetch github.com/Financial-Times/uuid-utils-go@1.0.0
Note1: this assumes your repo is already vendored (i.e. you ran: govendor init)
Note2: change in the fetch example above the appropriate tag release you want: @x.y.z
-
Generating an UUID based on another UUID:
originalUUID, _ := uuidutils.NewUUIDFromString("0000ea79-00a5-504e-a28d-11bd108b35ac") uuidDeriver := uuidutils.NewUUIDDeriverWith(uuidutils.IMAGE_SET) derivedUUID := uuidDeriver.From(originalUUID) revertToOriginalUUID := uuidDeriver.From(derivedUUID)
-
Generating an UUID from an random string (V3 version, i.e. using MD5 hashing):
someString := "1AB23ad1x34" generatedUUID := uuidutils.NewV3UUID(someString)
-
Generating an UUID from an URL (V5 version, i.e. using SHA1 hashing):
someString := "1AB23ad1x34" generatedUUID := uuidutils.NewDoubleDigestedV3UUID(someString)
-
Validating an UUID:
someUUID := "0000ea79-00a5-504e-a28d-11bd108b35ac" err := ValidateUUID(validUUID) if err != nil { // do something with the error }