当前位置:   article > 正文

golang UUID库总结_golang uuid short

golang uuid short
  • github.com/lithammer/shortuuid --> ApXTmAAr3kzdc4amUmbNAE
  • github.com/google/uuid --> 84b3a632-3caa-4eda-a38e-90490df4ed4d
  • github.com/rs/xid --> bp75p1fffgvhc04llp50
  • github.com/segmentio/ksuid --> 1Y4F8CGcQwckA4Iq02jtasTdnmL
  • github.com/kjk/betterguid --> -M0X5LUF2iRIATPVtgZc
  • github.com/oklog/ulid --> 01E1H1JSYGGVQZXPKJG0TY2WXD
  • github.com/sony/sonyflake --> 40528a7fc004b01
  • github.com/chilts/sid --> 1582193797082824800-0206775980367302090
  • github.com/satori/go.uuid --> 0dfaf3b2-4ea6-4066-80dd-71da02da5712
  • github.com/gitstliu/go-id-worker --> 2101641763637788672
package main

import (
	"fmt"
	"log"
	"math/rand"
	"time"

	"github.com/chilts/sid"
	guuid "github.com/google/uuid"
	"github.com/kjk/betterguid"
	"github.com/lithammer/shortuuid"
	"github.com/oklog/ulid"
	"github.com/rs/xid"
	"github.com/satori/go.uuid"
	"github.com/segmentio/ksuid"
	"github.com/sony/sonyflake"

	"github.com/gitstliu/go-id-worker"
)


func genShortUUID() {
	id := shortuuid.New()
	fmt.Printf("github.com/lithammer/shortuuid: %s\n", id)
}



func genUUID() {
	id := guuid.New()
	fmt.Printf("github.com/google/uuid:         %s\n", id.String())
}


func genXid() {
	id := xid.New()
	fmt.Printf("github.com/rs/xid:              %s\n", id.String())
}

func genKsuid() {
	id := ksuid.New()
	fmt.Printf("github.com/segmentio/ksuid:     %s\n", id.String())
}

func genBetterGUID() {
	id := betterguid.New()
	fmt.Printf("github.com/kjk/betterguid:      %s\n", id)
}

func genUlid() {
	t := time.Now().UTC()
	entropy := rand.New(rand.NewSource(t.UnixNano()))
	id := ulid.MustNew(ulid.Timestamp(t), entropy)
	fmt.Printf("github.com/oklog/ulid:          %s\n", id.String())
}

func genSonyflake() {
	flake := sonyflake.NewSonyflake(sonyflake.Settings{})
	id, err := flake.NextID()
	if err != nil {
		log.Fatalf("flake.NextID() failed with %s\n", err)
	}
	// Note: this is base16, could shorten by encoding as base62 string
	fmt.Printf("github.com/sony/sonyflake:      %x\n", id)
}

func genSid() {
	id := sid.Id()
	fmt.Printf("github.com/chilts/sid:          %s\n", id)
}

func genUUIDv4() {
	id, err := uuid.NewV4()
	if err != nil {
		log.Fatalf("uuid.NewV4() failed with %s\n", err)
	}
	fmt.Printf("github.com/satori/go.uuid:      %s\n", id)
}


func idwork(){
	currWoker := &idworker.IdWorker{} 
	currWoker.InitIdWorker(1000, 1)
	newId,_ := currWoker.NextId()
	fmt.Printf("github.com/gitstliu/go-id-worker:      %d\n", newId)
}

func main(){
	genShortUUID()

	genUUID()

	genXid()

	genKsuid()

	genBetterGUID()

	genUlid()

	genSonyflake()

	genSid()

	genUUIDv4()

	idwork()
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/850845
推荐阅读
相关标签
  

闽ICP备14008679号