1 Star 1 Fork 0

妙音 / oils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
key.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
妙音 提交于 2022-03-13 16:21 . style: lint
package level
import (
"encoding/binary"
"time"
)
// KeyASC 顺序Key.
func KeyASC(prefix []byte) []byte {
return KeyASCByInt(prefix, time.Now().UnixNano())
}
// KeyASCByInt 根据整数生成顺序Key.
func KeyASCByInt(prefix []byte, id int64) []byte {
bs := make([]byte, eight)
binary.BigEndian.PutUint64(bs, uint64(id))
return append(prefix, bs...)
}
// KeyASCByUint32 根据整数生成顺序Key.
func KeyASCByUint32(prefix []byte, id uint32) []byte {
bs := make([]byte, four)
binary.BigEndian.PutUint32(bs, id)
return append(prefix, bs...)
}
// KeyDESC 倒序Key.
func KeyDESC(prefix []byte) []byte {
return KeyDESCByInt(prefix, time.Now().UnixNano())
}
// KeyDESCByInt 根据整数生成倒序Key.
func KeyDESCByInt(prefix []byte, id int64) []byte {
bs := make([]byte, eight)
binary.BigEndian.PutUint64(bs, uint64(0-id))
return append(prefix, bs...)
}
// KeyDESCByUint32 uint32 倒序.
func KeyDESCByUint32(prefix []byte, id uint32) []byte {
bs := make([]byte, four)
binary.BigEndian.PutUint32(bs, 0-id)
return append(prefix, bs...)
}
1
https://gitee.com/xuender/oils.git
git@gitee.com:xuender/oils.git
xuender
oils
oils
v1.1.23

搜索帮助