id

package module
v0.0.0-...-2884ac9 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

id

generate id - snowflake, pika, stripe-id mix

get the package
> go get github.com/beyazit/id
example
func main() {
	generator := id.New([]*id.PrefixRecord{
		{
			Prefix:      "user",
			Description: "User ID",
			Secure:      false,
		},
		{
			Prefix:      "bearer",
			Description: "Bearer token",
			Secure:      true,
		},
	}, sonyflake.Settings{})

	fmt.Println(generator.Generate("user"))
	// user_NDM0NDAzNzQ0MDI5ODY4MzIx <nil>
	fmt.Println(generator.Generate("bearer"))
	// bearer_c182OTIwMzJmZGUwNmQ5ODAzMTQ0ZmQ0ZDlkNDliYzlhZF80MzQ0MDM3NDQwMjk5MzM4NTc <nil>
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodedID

type DecodedID struct {
	Prefix       string
	Tail         string
	Snowflake    uint64
	MachineID    uint64
	ElapsedTime  time.Duration
	Sequence     uint64
	PrefixRecord *PrefixRecord
}

type ID

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

func New

func New(prefixes []*PrefixRecord, st sonyflake.Settings) *ID

func (*ID) Deconstruct

func (i *ID) Deconstruct(id string) (*DecodedID, error)

func (*ID) Generate

func (i *ID) Generate(prefix string) (string, error)

type PrefixRecord

type PrefixRecord struct {
	Prefix      string
	Description string
	Secure      bool
}

Jump to

Keyboard shortcuts

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