【golang】go中常用的uuid插件

常见的uuid插件有:

github.com/google/uuid 4.8k

github.com/satori/go.uuid 4.8K

github.com/segmentio/ksuid 4.5k

github.com/oklog/ulid 3.9k

github.com/rs/xid 3.6k

github.com/sony/sonyflake 3.6k

github.com/gofrs/uuid 1.5k

github.com/lithammer/shortuuid 1.1k

github.com/nu7hatch/gouuid 417

github.com/kjk/betterguid 68

https://github.com/gitstliu/go-id-worker 57

github.com/chilts/sid 33


下面用github.com/google/uuid举例

package util

import (
	"github.com/google/uuid"
)



func CreateUuid(n int) string {
	// 494e09ff-29ec-426a-a3a1-362078085557
	uuid := uuid.New().String()
	if n <= 0 {
		return uuid
	}
	if n > len(uuid) {
		n = len(uuid) - 1
	}
	return uuid[:n]
}

你可能感兴趣的:(Golang,golang,开发语言,后端)