Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/base32"
- "encoding/base64"
- "encoding/hex"
- "fmt"
- "github.com/btcsuite/btcutil/base58"
- "github.com/google/uuid"
- )
- // Example output:
- // Binary: [52 155 71 198 73 40 76 110 178 168 24 215 190 191 78 205]
- // Binary text: [51 52 57 98 52 55 99 54 45 52 57 50 56 45 52 99 54 101 45 98 50 97 56 45 49 56 100 55 98 101 98 102 52 101 99 100]
- // Text: 349b47c6-4928-4c6e-b2a8-18d7bebf4ecd
- // Hex binary: [51 52 57 98 52 55 99 54 52 57 50 56 52 99 54 101 98 50 97 56 49 56 100 55 98 101 98 102 52 101 99 100]
- // Hex: 349b47c649284c6eb2a818d7bebf4ecd
- // base58 binary: [55 86 109 112 104 117 77 116 76 122 69 122 50 51 100 66 65 99 105 118 106 87]
- // base58: 7VmphuMtLzEz23dBAcivjW
- // base64 binary: [78 74 116 72 120 107 107 111 84 71 54 121 113 66 106 88 118 114 57 79 122 81 61 61]
- // base64: NJtHxkkoTG6yqBjXvr9OzQ==
- // base32 binary: [71 83 78 85 80 82 83 74 70 66 71 71 53 77 86 73 68 68 76 51 53 80 50 79 90 85 61 61 61 61 61 61]
- // base32: GSNUPRSJFBGG5MVIDDL35P2OZU======
- // Length of the guid in binary: 16
- // Length of the base58 representation of the guid in binary: 22
- // Length of the base64 representation of the guid in binary: 24
- // Length of the base32 representation of the guid in binary: 32
- func main() {
- guid := uuid.New()
- guidBin, err := guid.MarshalBinary()
- handleError(err)
- guidStr, err := guid.MarshalText()
- handleError(err)
- guidHex := hex.EncodeToString(guidBin)
- guidBase58 := base58.Encode(guidBin)
- guidBase64 := base64.StdEncoding.EncodeToString(guidBin)
- guidBase32 := base32.StdEncoding.EncodeToString(guidBin)
- fmt.Println("Binary:", guidBin)
- fmt.Println("Binary text:", guidStr)
- fmt.Println("Text:", string(guidStr))
- fmt.Println("Hex binary:", []byte(guidHex))
- fmt.Println("Hex:", guidHex)
- fmt.Println("base58 binary:", []byte(guidBase58))
- fmt.Println("base58:", guidBase58)
- fmt.Println("base64 binary:", []byte(guidBase64))
- fmt.Println("base64:", guidBase64)
- fmt.Println("base32 binary:", []byte(guidBase32))
- fmt.Println("base32:", guidBase32)
- fmt.Println("Length of the guid in binary:", len(guidBin))
- fmt.Println("Length of the base58 representation of the guid in binary:", len([]byte(guidBase58)))
- fmt.Println("Length of the base64 representation of the guid in binary:", len([]byte(guidBase64)))
- fmt.Println("Length of the base32 representation of the guid in binary:", len([]byte(guidBase32)))
- }
- func handleError(err error) {
- if err != nil {
- panic(err)
- }
- }
Add Comment
Please, Sign In to add comment