pika

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 9 Imported by: 1

README

pika go

Golang implementation for pika.

Install

To install, run

go get github.com/knvi/pika@v1.1.0

Usage

package main

import "github.com/knvi/pika"

func main() {
	prefixes := []pika.PikaPrefixDefinition{
		{
			Prefix:      "test",
			Description: "test",
			Secure:      false,
		},
	}
	
	p := pika.NewPika(prefixes, pika.PikaInitOptions{
		Epoch:            1650153600000,
		NodeID:           622,
		DisableLowercase: true,
	})
	
	id := p.Gen("test")

	println(id)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_EPOCH int64 = 1640995200000 // Jan 1, 2022
View Source
var VALID_PREFIX = regexp.MustCompile(`^[a-z0-9_]+$`)

Functions

func ComputeNodeID

func ComputeNodeID() int

Types

type DecodedPika

type DecodedPika struct {
	Prefix       string
	Tail         string
	Snowflake    int64
	NodeID       int
	Seq          int
	Version      int
	Epoch        int64
	PrefixRecord PikaPrefixDefinition
}

type DeconstructedSnowflake

type DeconstructedSnowflake struct {
	ID        int64
	Timestamp int64
	NodeID    int
	Seq       int
	Epoch     int64
}

type Pika

type Pika struct {
	Prefixes         map[string]PikaPrefixDefinition
	Epoch            int64
	NodeID           int
	DisableLowercase bool
	// contains filtered or unexported fields
}

func NewPika

func NewPika(prefixes []PikaPrefixDefinition, opts PikaInitOptions) *Pika

func (*Pika) Decode

func (p *Pika) Decode(id string) (DecodedPika, error)

func (*Pika) Gen

func (p *Pika) Gen(prefix string) string

type PikaInitOptions

type PikaInitOptions struct {
	Epoch            int64
	NodeID           int
	DisableLowercase bool
}

type PikaPrefixDefinition

type PikaPrefixDefinition struct {
	Prefix      string
	Description string
	Secure      bool
}

type Snowflake

type Snowflake struct {
	Epoch  int64
	NodeID int
	Seq    int
	LastTS int64
}

func NewSnowflake

func NewSnowflake(epoch int64, node_id int) *Snowflake

func (*Snowflake) Deconstruct

func (s *Snowflake) Deconstruct(id string) *DeconstructedSnowflake

func (*Snowflake) Gen

func (s *Snowflake) Gen() string

-- Snowflake Struct Functions

func (*Snowflake) GenWithTimestamp

func (s *Snowflake) GenWithTimestamp(timestamp int64) string

Jump to

Keyboard shortcuts

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