Documentation ¶
Index ¶
- func Equal(u1 uid.UUID, u2 uid.UUID) bool
- func FromBytes(input []byte) (u uid.UUID, err error)
- func FromBytesOrNil(input []byte) uid.UUID
- func FromString(input string) (u uid.UUID, err error)
- func FromStringOrNil(input string) uid.UUID
- func KSUIDCompare(a, b ksuid.KSUID) int
- func KSUIDFromBytes(b []byte) (ksuid.KSUID, error)
- func KSUIDFromParts(t time.Time, payload []byte) (ksuid.KSUID, error)
- func KSUIDIsSorted(ids []ksuid.KSUID) bool
- func KSUIDParse(s string) (ksuid.KSUID, error)
- func KSUIDSort(ids []ksuid.KSUID)
- func NewKSUID() ksuid.KSUID
- func NewKSUIDRandom() (uid ksuid.KSUID, err error)
- func NewKSUIDRandomWithTime(t time.Time) (uid ksuid.KSUID, err error)
- func NewV1() uid.UUID
- func NewV2(domain byte) uid.UUID
- func NewV3(ns uid.UUID, name string) uid.UUID
- func NewV4() uid.UUID
- func NewV5(ns uid.UUID, name string) uid.UUID
- func NewXID() xid.ID
- func NewXIDWithTime(time time.Time) xid.ID
- func RequestID() string
- func RequestIDCanonicalFormat() string
- func ToRequestID(u uid.UUID) string
- func XIDFromBytes(b []byte) (xid.ID, error)
- func XIDFromString(id string) (xid.ID, error)
- func XIDSort(ids []xid.ID)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromBytes ¶
FromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.
func FromBytesOrNil ¶
FromBytesOrNil returns UUID converted from raw byte slice input. Same behavior as FromBytes, but returns a Nil UUID on error.
func FromString ¶
FromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.
func FromStringOrNil ¶
FromStringOrNil returns UUID parsed from string input. Same behavior as FromString, but returns a Nil UUID on error.
func KSUIDCompare ¶
KSUIDCompare implements comparison for KSUID type.
func KSUIDFromBytes ¶
KSUIDFromBytes constructs a KSUID from a 20-byte binary representation.
func KSUIDFromParts ¶
KSUIDFromParts constructs a KSUID from constituent parts.
func KSUIDIsSorted ¶
KSUIDIsSorted checks whether a slice of KSUIDs is sorted
func KSUIDParse ¶
KSUIDParse decodes a string-encoded representation of a KSUID object.
func NewKSUID ¶
NewKSUID generates a new KSUID.
Example ¶
package main import ( "encoding/hex" "fmt" "strings" "github.com/segmentio/ksuid" "github.com/v8fg/kit4go/uuid" ) func printKSUIDInspect(id ksuid.KSUID) { const inspectFormat = ` REPRESENTATION: String: %v Raw: %v COMPONENTS: Time: %v Timestamp: %v Payload: %v ` fmt.Printf(inspectFormat, id.String(), strings.ToUpper(hex.EncodeToString(id.Bytes())), id.Time().UTC().String(), id.Timestamp(), strings.ToUpper(hex.EncodeToString(id.Payload())), ) } func main() { testKSUIDStr := "2FwgbLS72ILDWFEhMSFKCRJBN7M" testKSUID, _ := uuid.KSUIDParse(testKSUIDStr) printKSUIDInspect(testKSUID) }
Output: REPRESENTATION: String: 2FwgbLS72ILDWFEhMSFKCRJBN7M Raw: 0FD1D076606A0AB5DC14C70CD26FD2B6ED2A2D9C COMPONENTS: Time: 2022-10-10 13:30:30 +0000 UTC Timestamp: 265408630 Payload: 606A0AB5DC14C70CD26FD2B6ED2A2D9C
func NewKSUIDRandom ¶
NewKSUIDRandom generates a new KSUID with now timestamp.
func NewKSUIDRandomWithTime ¶
NewKSUIDRandomWithTime generates a new KSUID with the given timestamp.
func NewXID ¶
NewXID generates a globally unique ID.
Example ¶
package main import ( "encoding/hex" "fmt" "strings" "github.com/rs/xid" "github.com/v8fg/kit4go/uuid" ) func printXIDInspect(id xid.ID) { const inspectFormat = ` REPRESENTATION: String: %v Raw: %v COMPONENTS: Time: %v Counter: %v Machine: %v Pid: %v ` fmt.Printf(inspectFormat, id.String(), strings.ToUpper(hex.EncodeToString(id.Bytes())), id.Time().UTC().String(), id.Counter(), strings.ToUpper(hex.EncodeToString(id.Machine())), id.Pid(), ) } func main() { testXIDStr := "cd1qnegnhc7lcditguhg" testXID, _ := uuid.XIDFromString(testXIDStr) printXIDInspect(testXID) }
Output: REPRESENTATION: String: cd1qnegnhc7lcditguhg Raw: 6343ABBA178B0F56365D87A3 COMPONENTS: Time: 2022-10-10 05:20:58 +0000 UTC Counter: 6129571 Machine: 178B0F Pid: 22070
func NewXIDWithTime ¶
NewXIDWithTime generates a globally unique ID with the passed in time.
func RequestID ¶
func RequestID() string
RequestID returns the request ID with UUID V4, in hash-like format, 32 chars.
Example ¶
package main import ( "fmt" "github.com/v8fg/kit4go/uuid" ) func main() { testUIDHashLikeFormat := "10da441c38704f06a78c4dfef1c9acea" testUIDCanonicalFormat := "10da441c-3870-4f06-a78c-4dfef1c9acea" testUUID, _ := uuid.FromString(testUIDHashLikeFormat) testUUID2, _ := uuid.FromString(testUIDCanonicalFormat) fmt.Printf("[ExampleRequestID] %v\n", uuid.ToRequestID(testUUID)) fmt.Printf("[ExampleRequestID] %v\n", uuid.ToRequestID(testUUID2)) }
Output: [ExampleRequestID] 10da441c38704f06a78c4dfef1c9acea [ExampleRequestID] 10da441c38704f06a78c4dfef1c9acea
func RequestIDCanonicalFormat ¶
func RequestIDCanonicalFormat() string
RequestIDCanonicalFormat returns the request ID with UUID V4, in canonical format, 36 chars.
Example ¶
package main import ( "fmt" "github.com/v8fg/kit4go/uuid" ) func main() { testUIDHashLikeFormat := "10da441c38704f06a78c4dfef1c9acea" testUIDCanonicalFormat := "10da441c-3870-4f06-a78c-4dfef1c9acea" testUUID, _ := uuid.FromString(testUIDHashLikeFormat) testUUID2, _ := uuid.FromString(testUIDCanonicalFormat) fmt.Printf("[ExampleRequestIDCanonicalFormat] %v\n", testUUID.String()) fmt.Printf("[ExampleRequestIDCanonicalFormat] %v\n", testUUID2.String()) }
Output: [ExampleRequestIDCanonicalFormat] 10da441c-3870-4f06-a78c-4dfef1c9acea [ExampleRequestIDCanonicalFormat] 10da441c-3870-4f06-a78c-4dfef1c9acea
func ToRequestID ¶
ToRequestID converts the uuid with UUID V4 to a request ID, in hash-like format, 32 chars.
func XIDFromBytes ¶
XIDFromBytes convert the byte array representation of `ID` back to `ID`
func XIDFromString ¶
XIDFromString reads an ID from its string representation
Types ¶
This section is empty.