Last active
March 10, 2016 06:56
-
-
Save xigang/efb643cc6b5c9298f43f to your computer and use it in GitHub Desktop.
根据需要生成指定的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 ( | |
"flag" | |
"fmt" | |
"log" | |
uuid "github.com/nu7hatch/gouuid" | |
) | |
func generateUUID() (id string, err error) { | |
var uid *uuid.UUID | |
uid, err = uuid.NewV4() | |
if err != nil { | |
log.Fatal("generate uuid error.", err) | |
return | |
} | |
id = uid.String() | |
return | |
} | |
var ( | |
count = flag.Int("num", 1, "Usage: generate_uuid -num=?") | |
) | |
func main() { | |
flag.Parse() | |
for i := 0; i < *count; i++ { | |
uid, err := generateUUID() | |
if err != nil { | |
return | |
} | |
fmt.Println(uid) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment