1 Star 0 Fork 0

zhouqunjie / uuid

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
machine.go 805 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhouqj 提交于 2022-05-11 22:34 . init
// This file is part of the guuid package
//
// (c) Dreamans <dreamans@163.com>
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
package guuid
import (
"crypto/md5"
"os"
"strconv"
"strings"
)
var machineId []byte = machineHash()
func machineHash() (machHash []byte) {
posixPID := posixPid()
machineName := machineHostname()
randId := rand()
machine := strings.Join([]string{
machineName,
strconv.Itoa(posixPID),
uint32ToHexString(randId),
}, ",")
md5Ctx := md5.New()
md5Ctx.Write([]byte(machine))
machHash = md5Ctx.Sum(nil)
return
}
func machineHostname() string {
host, err := os.Hostname()
if err != nil {
host = "localhost"
}
return host
}
func posixPid() int {
return int(os.Getpid())
}
Go
1
https://gitee.com/zhouqunjie/uuid.git
git@gitee.com:zhouqunjie/uuid.git
zhouqunjie
uuid
uuid
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891