commit
4741d211f2
@ -0,0 +1,11 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: clone
|
||||
|
||||
steps:
|
||||
- name: test-golang
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -v ./...
|
@ -0,0 +1,8 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
gomod.sh
|
||||
/vendor/
|
@ -0,0 +1,25 @@
|
||||
<h1>
|
||||
<a href="https://www.dtapp.net/">Golang Uuid</a>
|
||||
</h1>
|
||||
|
||||
📦 Golang Uuid
|
||||
|
||||
[comment]: <> (go)
|
||||
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gouuid?status.svg)](https://pkg.go.dev/go.dtapp.net/gouuid)
|
||||
[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gouuid/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gouuid)
|
||||
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gouuid )](https://goreportcard.com/report/go.dtapp.net/gouuid)
|
||||
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/gouuid)
|
||||
|
||||
#### 安装使用
|
||||
|
||||
```go
|
||||
go get -v -u go.dtapp.net/gouuid
|
||||
```
|
||||
|
||||
#### 导入
|
||||
|
||||
```go
|
||||
import (
|
||||
"go.dtapp.net/gouuid"
|
||||
)
|
||||
```
|
@ -0,0 +1,18 @@
|
||||
package gouuid
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GetUuId 获取唯一ID
|
||||
func GetUuId() string {
|
||||
unix32bits := uint32(time.Now().UTC().Unix())
|
||||
buff := make([]byte, 12)
|
||||
numRead, err := rand.Read(buff)
|
||||
if numRead != len(buff) || err != nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x-%x", unix32bits, buff[0:2], buff[2:4], buff[4:6], buff[6:8], buff[8:])
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package gouuid
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetUuId(t *testing.T) {
|
||||
t.Log(GetUuId())
|
||||
}
|
||||
|
||||
func BenchmarkGetUuId(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.Log(GetUuId())
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package gouuid
|
||||
|
||||
const Version = "1.0.0"
|
Loading…
Reference in new issue