Created
September 28, 2016 23:38
-
-
Save PaluMacil/1a94dc5edacd5b3d68722d2ff3be0002 to your computer and use it in GitHub Desktop.
Simple playing with Nuhach's uuid.
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 ( | |
"encoding/base64" | |
"fmt" | |
uuid "github.com/nu7hatch/gouuid" // It seems that github.com/satori/go.uuid has more advanced functionality. | |
) | |
func main() { | |
u, e := uuid.NewV4() | |
if e != nil { | |
panic("Couldn't generate a uuid v4.") | |
} | |
fmt.Println("uuid is [16]bytes:", u) | |
fmt.Println("uuid.String(), which is 36 bytes:", u.String()) | |
s := base64.StdEncoding.EncodeToString([]byte(u.String())) | |
fmt.Println("base64:", s) | |
original, _ := base64.StdEncoding.DecodeString(s) | |
fmt.Println("Original uuid as bytes:", original) | |
fmt.Println("Original uuid:", string(original)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment