id

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package id 提供了生成数字和字符串 ID 的方法,同时支持 JSON 对 ID 的加解密

Example Usage

import "nbserver/common/id"

func main() {
  id := id.GenerateID()
}

Benchmark History

goos: windows
goarch: amd64
pkg: nbserver/common/id
cpu: Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
BenchmarkIDGeneration
BenchmarkIDGeneration-16        89568280                13.29 ns/op

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID uint64

ID 标准数字唯一键

func GenerateID

func GenerateID() ID

GenerateID 返回一个随机生成的 64 字节 ID。这个函数进程安全 这个方法大概花费 13.29 ns, 不产出任何内存垃圾

func ParseID

func ParseID(s string) (ID, error)

ParseID 转译给定字符串为 ID

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON 编码 ID 为 JSON encoding

func (ID) String

func (id ID) String() string

String 返回 ID 为 hex 字符串

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON 解码 给定数据为 Json encoding 或 Json 数字

type WithID

type WithID struct {
	// contains filtered or unexported fields
}

WithID 给结构体、对象赋予 ID 功能

func (*WithID) GetID

func (w *WithID) GetID() ID

GetID 获取 ID

func (*WithID) InitID

func (w *WithID) InitID()

InitID 初始化 ID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL