Documentation
¶
Overview ¶
Package utils provides utility functions for common operations including UUID generation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultString ¶ added in v0.24.0
DefaultString returns the value if it's not empty, otherwise returns the default value
func ExpandPath ¶
func ExpandPathPOSIX ¶ added in v0.19.0
Example ¶
p, err := ExpandPathPOSIX("~/test")
if err != nil {
log.Fatal(err)
}
_, last := filepath.Split(p)
fmt.Println(last)
p, _ = ExpandPathPOSIX("~NONEXISTINGUSER/path/to/file")
fmt.Println(p)
p, _ = ExpandPathPOSIX("/path/to/file/tilde/~")
fmt.Println(p)
p, _ = ExpandPathPOSIX("")
fmt.Println(p)
p, _ = ExpandPathPOSIX("")
fmt.Println(p)
Output: test ~NONEXISTINGUSER/path/to/file /path/to/file/tilde/~
func GenerateUUID ¶ added in v0.24.0
func GenerateUUID() string
GenerateUUID generates a random UUID v4 string. Returns a 36-character UUID in format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
Example:
id := utils.GenerateUUID() // Output: "550e8400-e29b-41d4-a716-446655440000"
func GenerateUUIDShort ¶ added in v0.24.0
func GenerateUUIDShort() string
GenerateUUIDShort generates a short 8-character UUID string. Higher collision probability than full UUID - use carefully in production.
Example:
id := utils.GenerateUUIDShort() // Output: "550e8400"
func GenerateUUIDv5 ¶ added in v0.24.0
GenerateUUIDv5 generates a deterministic UUID v5 from namespace and fields. Same inputs always produce the same UUID. Fields are joined with '|' separator.
Parameters:
- namespace: UUID namespace (e.g., uuid.NameSpaceDNS)
- fields: Non-empty strings to generate UUID from
Returns error if fields is empty or contains empty strings.
Example:
id, err := utils.GenerateUUIDv5(uuid.NameSpaceDNS, []string{"user", "john.doe"})
Types ¶
This section is empty.