本文整理汇总了Golang中github.com/twinj/uuid.NewV4函数的典型用法代码示例。如果您正苦于以下问题:Golang NewV4函数的具体用法?Golang NewV4怎么用?Golang NewV4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewV4函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupIDs
func (s *Server) setupIDs() error {
clusterIDPath := filepath.Join(s.dataDir, clusterIDFilename)
clusterID, err := s.readID(clusterIDPath)
if err != nil && !os.IsNotExist(err) {
return err
}
if clusterID == "" {
clusterID = uuid.NewV4().String()
s.writeID(clusterIDPath, clusterID)
}
s.ClusterID = clusterID
serverIDPath := filepath.Join(s.dataDir, serverIDFilename)
serverID, err := s.readID(serverIDPath)
if err != nil && !os.IsNotExist(err) {
return err
}
if serverID == "" {
serverID = uuid.NewV4().String()
s.writeID(serverIDPath, serverID)
}
s.ServerID = serverID
return nil
}
示例2: Example
func Example() {
saver := new(savers.FileSystemSaver)
saver.Report = true
saver.Duration = time.Second * 3
// Run before any v1 or v2 UUIDs to ensure the saver takes
uuid.RegisterSaver(saver)
u1 := uuid.NewV1()
fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)
uP, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
u3 := uuid.NewV3(uP, uuid.Name("test"))
u4 := uuid.NewV4()
fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)
u5 := uuid.NewV5(uuid.NamespaceURL, uuid.Name("test"))
if uuid.Equal(u1, u3) {
fmt.Printf("Will never happen")
}
fmt.Print(uuid.Sprintf(uuid.CurlyHyphen, u5))
uuid.SwitchFormat(uuid.BracketHyphen)
}
示例3: Test_AllEnvelopes
func (s *EnvelopeRepositorySuite) Test_AllEnvelopes() {
e1 := gledger.Envelope{
UUID: uuid.NewV4().String(),
Name: "Test Envelope 1",
Type: "income",
Balance: 10,
}
e2 := gledger.Envelope{
UUID: uuid.NewV4().String(),
Name: "Test Envelope 2",
Type: "expense",
}
s.mustExec(`INSERT INTO envelopes VALUES (
$1, $2, '2016-08-30T00:00:00Z', now(), $3
)`, e1.UUID, e1.Name, e1.Type)
s.mustExec(`INSERT INTO envelopes VALUES (
$1, $2, '2016-08-30T00:00:01Z', now(), $3
)`, e2.UUID, e2.Name, e2.Type)
s.mustExec(`INSERT INTO transactions VALUES ($1, $2, now(), 'payee', 10, 'f', 'f', now(), now(), $3)`, uuid.NewV4(), "cadd0722-6fd1-47ff-b390-b53307cc8c01", e1.UUID)
es, err := AllEnvelopes(s.tx.Query)()
if s.NoError(err) {
s.Equal([]gledger.Envelope{e1, e2}, es)
}
}
示例4: InsertPost
func InsertPost(title []byte, slug string, markdown []byte, html []byte, featured bool, isPage bool, published bool, image []byte, created_at time.Time, created_by int64) (int64, error) {
status := "draft"
if published {
status = "published"
}
writeDB, err := readDB.Begin()
if err != nil {
writeDB.Rollback()
return 0, err
}
var result sql.Result
if published {
result, err = writeDB.Exec(stmtInsertPost, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), title, slug, markdown, html, featured, isPage, status, image, created_by, created_at, created_by, created_at, created_by, created_at, created_by)
} else {
result, err = writeDB.Exec(stmtInsertPost, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), title, slug, markdown, html, featured, isPage, status, image, created_by, created_at, created_by, created_at, created_by, nil, nil)
}
if err != nil {
writeDB.Rollback()
return 0, err
}
postId, err := result.LastInsertId()
if err != nil {
writeDB.Rollback()
return 0, err
}
return postId, writeDB.Commit()
}
示例5: TestProcessCancelCommandMessage
// TestProcessCancelCommandMessage tests that processCancelCommandMessage calls all the expected APIs
// on receiving a cancel message.
func TestProcessCancelCommandMessage(t *testing.T) {
testCase := TestCaseCancelCommand{
MsgToCancelID: uuid.NewV4().String(),
MsgID: uuid.NewV4().String(),
InstanceID: "i-400e1090",
}
testProcessCancelCommandMessage(t, testCase)
}
示例6: TestTrak
// For now, it doesn't actually test much to be honest
func TestTrak(t *testing.T) {
log.Printf("### TRAK.TRANSACTION")
tr := &Transaction{
ID: uuid.NewV4().String(),
Timestamp: time.Now(),
Author: uuid.NewV4().String(),
Action: "buy food and eat",
Payload: []Payload{
Payload{
ID: uuid.NewV4().String(),
Table: "transactions",
Action: "insert",
Values: map[string]interface{}{
"timestamp": time.Now(),
"item": uuid.NewV4().String(),
"buyer": uuid.NewV4().String(),
},
},
Payload{
ID: uuid.NewV4().String(),
Table: "accounts",
Action: "update",
Values: map[string]interface{}{
"money": 23712,
},
},
Payload{
ID: uuid.NewV4().String(),
Table: "accounts",
Action: "update",
Values: map[string]interface{}{
"money": 82139,
},
},
Payload{
ID: uuid.NewV4().String(),
Table: "players",
Action: "update",
Values: map[string]interface{}{
"hunger": 0,
"last_meal": time.Now(),
},
},
Payload{
ID: uuid.NewV4().String(),
Table: "items",
Action: "delete",
},
},
}
trJ, _ := tr.JSON()
log.Printf("Transaction JSON: %s", trJ)
trS, _, _ := tr.SQL()
log.Printf("Transaction SQL: %s", trS)
}
示例7: generateKey
func generateKey() (string, string, error) {
key := uuid.NewV4().String()
secretKey := uuid.NewV4().String()
_, err := Conn.Do("SADD", "api-keys", key)
if err != nil {
return "", "", err
}
_, err = Conn.Do("HSET", "key:"+key, "secret", secretKey)
if err != nil {
return "", "", err
}
_, err = Conn.Do("SADD", "key:"+key+":permissions", GetPermission, UploadPermission)
return key, secretKey, err
}
示例8: Initialize
func Initialize() error {
// If journey.db does not exist, look for a Ghost database to convert
if !helpers.FileExists(filenames.DatabaseFilename) {
// Convert Ghost database if available (time format needs to change to be compatible with journey)
migration.Ghost()
}
// Open or create database file
var err error
readDB, err = sql.Open("sqlite3", filenames.DatabaseFilename)
if err != nil {
return err
}
readDB.SetMaxIdleConns(256) // TODO: is this enough?
err = readDB.Ping()
if err != nil {
return err
}
currentTime := time.Now()
_, err = readDB.Exec(stmtInitialization, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime)
// TODO: Is Commit()/Rollback() needed for DB.Exec()?
if err != nil {
return err
}
err = checkBlogSettings()
if err != nil {
return err
}
return nil
}
示例9: saveImage
func saveImage(image string) (string, error) {
if image == "" {
return "", nil
}
var number = uuid.NewV4()
var newImage = "download/" + uuid.Formatter(number, uuid.CurlyHyphen)
out, error := os.Create(newImage)
if error != nil {
return "", error
}
defer out.Close()
response, error := http.Get(image)
if error != nil {
return "", error
}
defer response.Body.Close()
pix, error := ioutil.ReadAll(response.Body)
if error != nil {
return "", error
}
_, error = io.Copy(out, bytes.NewReader(pix))
if error != nil {
return "", error
}
return newImage, nil
}
示例10: NewStatistics
// NewStatistics creates an expvar-based map. Within there "name" is the Measurement name, "tags" are the tags,
// and values are placed at the key "values".
// The "values" map is returned so that statistics can be set.
func NewStatistics(name string, tags map[string]string) (string, *kexpvar.Map) {
key := uuid.NewV4().String()
m := &kexpvar.Map{}
m.Init()
// Set the name
nameVar := &kexpvar.String{}
nameVar.Set(name)
m.Set("name", nameVar)
// Set the tags
tagsVar := &kexpvar.Map{}
tagsVar.Init()
for k, v := range tags {
value := &kexpvar.String{}
value.Set(v)
tagsVar.Set(k, value)
}
m.Set("tags", tagsVar)
// Create and set the values entry used for actual stats.
statMap := &kexpvar.Map{}
statMap.Init()
m.Set("values", statMap)
// Set new statsMap on the top level map.
stats.Set(key, m)
return key, statMap
}
示例11: ParseMessage
func ParseMessage(recipients []string, sender string, data []byte) (msg Msg, err error) {
msg.Sender, err = ParseAddress(sender)
if err != nil {
return msg, err
}
for _, rcpt := range recipients {
rcptAddr, err := ParseAddress(rcpt)
if err != nil {
return msg, err
}
msg.Rcpt = append(msg.Rcpt, rcptAddr)
}
message, err := mail.ReadMessage(bytes.NewReader(data))
if err != nil {
return msg, err
}
msg.Message = *message
msg.MessageId = msg.Message.Header.Get("message-id")
if msg.MessageId == "" {
id := uuid.NewV4()
uuid.SwitchFormat(uuid.Clean)
msg.MessageId = id.String()
}
msg.RcptDomains = make(map[string]int)
for _, d := range msg.Rcpt {
msg.RcptDomains[d.Domain] = msg.RcptDomains[d.Domain] + 1
}
return msg, nil
}
示例12: BenchmarkNewV4
func BenchmarkNewV4(b *testing.B) {
for i := 0; i < b.N; i++ {
uuid.NewV4()
}
b.StopTimer()
b.ReportAllocs()
}
示例13: Create
func (as accountService) Create(a Account) (Account, error) {
if a.UUID == "" {
a.UUID = uuid.NewV4().String()
}
return a, as.saveAccount(a)
}
示例14: Create
func (ts transactionService) Create(t Transaction) (Transaction, error) {
if t.UUID == "" {
t.UUID = uuid.NewV4().String()
}
return t, ts.saveTransaction(t)
}
示例15: handleUpload
// Handles upload requests.
func handleUpload(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
// parse HTML template
t, err := template.New("presign").Parse(htmlDocument)
if err != nil {
c.Errorf("Error parsing template: %s", err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
// a unique key to upload
id := uuid.NewV4().String()
// AWS S3 credentials
creds := &s3.Credentials{
Region: regionName,
Bucket: bucketName,
AccessKeyID: accessKeyID,
SecretAccessKey: secretAccessKey,
}
// create pre-signed POST details
opts := &s3.PolicyOptions{5, 1024000}
post, err := s3.NewPresignedPOST(id, creds, opts)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
// render HTML form
t.Execute(w, post)
}