golang UUID v1,v2,v3,v4和v5

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang UUID v1,v2,v3,v4和v5相关的知识,希望对你有一定的参考价值。

package main

import (
	"fmt"
	"github.com/satori/go.uuid"
)

func main() {
	// Creating UUID Version 1
	uuid1 := uuid.NewV1()
	fmt.Printf("UUIDv1: %s\n", uuid1)

	// Creating UUID Version 2 - Domain Person
	uuid2 := uuid.NewV2(uuid.DomainPerson)
	fmt.Printf("UUIDv2: %s\n", uuid2)

	// Creating UUID Version 2 - Domain Group
	uuid2b := uuid.NewV2(uuid.DomainGroup)
	fmt.Printf("UUIDv2: %s\n", uuid2b)

	// Creating UUID Version 2 - Domain Organization
	uuid2c := uuid.NewV2(uuid.DomainOrg)
	fmt.Printf("UUIDv2: %s\n", uuid2c)

	// Creating UUID Version 3
	uuid3 := uuid.NewV3(uuid.NamespaceDNS, "someplace.org")
	fmt.Printf("UUIDv2: %s\n", uuid3)

	// Creating UUID Version 4
	uuid4 := uuid.NewV4()
	fmt.Printf("UUIDv4: %s\n", uuid4)

	// Creating UUID Version 5
	uuid5 := uuid.NewV5(uuid.NamespaceURL, "blaghdblagh.com")
	fmt.Printf("UUIDv5: %s\n", uuid5)

	// Parsing UUID from string input
	u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")

	if err != nil {
		fmt.Printf("Something gone wrong: %s", err)
	}

	fmt.Printf("Successfully parsed: %s\n", u2)
}

golang

    for _, v := range resultObjects 
        sd, exist := m[v.Endpoint]
        if !exist 
                        sd := new(SavedData) // sd = new(SavedData)
            sd.Ip = v.Endpoint
            sd.StartTime = time.Unix(start, 0)
            sd.EndTime = time.Unix(end, 0)

            m[v.Endpoint] = sd
        
        ...
            ...
                ...

        sd.CpuMax = float64(max)
        sd.CpuMin = min

        m[v.Endpoint] = sd
    

跑这段代码会出现这个问题:

panic: runtime error: invalid memory address or nil pointer dereference

因为忽略了作用域

以上是关于golang UUID v1,v2,v3,v4和v5的主要内容,如果未能解决你的问题,请参考以下文章

UUID-五个版本-v1|v2|v3|v4|v5-使用说明

YOLO系列阅读笔记V1 V2 V3 V4

51nod Bash游戏(V1,V2,V3,V4(斐波那契博弈))

字符串

GoogLeNet(Inception v1-v4)

Android每日一题:v3签名key和v2还有v1有啥区别