什么是 UUID?
UUID 是Universally Unique Identifier的缩写,即通用唯一识别码。
uuid的目的是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定。如此一来,每个人都可以建立不与其它人冲突的 uuid。
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems.
Go 中使用 UUID
目前,golang中的uuid还没有纳入标准库,我们使用github上的开源库:
$ go get -u github.com/satori/go.uuid
使用:
package main
import (
"fmt"
"github.com/satori/go.uuid"
)
func main() {
// 创建
u1 := uuid.NewV4()
fmt.Printf("UUIDv4: %s\n", u1)
// 解析
u2, err := uuid.FromString("f5394eef-e576-4709-9e4b-a7c231bd34a4")
if err != nil {
fmt.Printf("Something gone wrong: %s", err)
return
}
fmt.Printf("Successfully parsed: %s", u2)
}
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper