Created
July 3, 2022 12:23
-
-
Save veggiemonk/fc6e74de123905c5a06a3e76deb92332 to your computer and use it in GitHub Desktop.
[experimental] Encode UUID as string of numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/big" | |
"strings" | |
"github.com/google/uuid" | |
) | |
// Go Playground: https://go.dev/play/p/RBzt677Nqeq | |
func main() { | |
u1 := strings.ReplaceAll(uuid.New().String(), "-", "") | |
fmt.Println("UUID string:", u1) | |
// encode UUID as string of numbers | |
id := new(big.Int) | |
if _, ok := id.SetString(strings.ReplaceAll(uuid.New().String(), "-", ""), 16); ok { | |
u2 := id.String() | |
fmt.Println("UUID as numbers:", u2) | |
} else { | |
fmt.Errorf("failed to convert uuid to bigint") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment