Help us shape the future of Go! Take the 2026 Go Developer Survey

sequence

package module
v0.0.0-...-a577d6c Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 2 Imported by: 1

README

go-seq

Painless alphabetical sequential IDs.

Documentation

Visit godoc.

Get this package

$ go get github.com/sugoiuguu/go-seq

Example

New

// create a new sequence
seq := sequence.NewSeq()

fmt.Printf("%q\n", seq.Next())

Encode

// create a new sequence
seq := sequence.NewSeq()

// create a new encoder that outputs to stdout
dec := json.NewEncoder(os.Stdout)

if err := enc.Encode(seq); err != nil {
    panic(err)
}

Decode

// the sequence we'll initialize
var seq sequence.Seq

// create a new decoder that reads from stdin
dec := json.NewDecoder(os.Stdin)

if err := dec.Decode(&seq); err != nil {
    panic(err)
}

fmt.Printf("%q\n", seq.Next())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidByte = errors.New("sequence: invalid byte in initializer")
	ErrNotFreeable = errors.New("sequence: can't free value")
)

Functions

func Cmp

func Cmp(x, y []byte) int

Compare two IDs, x and y; if x == y, this function returns 0; if x > y, it returns 1; if x < y, it returns -1.

Types

type Seq

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

func NewSeq

func NewSeq() *Seq

Returns a new sequence starting at 'a'.

func NewSeqFrom

func NewSeqFrom(value []byte) (*Seq, error)

Returns a new sequence starting at a particular value.

func (*Seq) Free

func (s *Seq) Free(value []byte) error

Frees an ID that has already been returned with Next(); the free'd ID will be returned on the next Next() call.

func (*Seq) Next

func (s *Seq) Next(nextBuf []byte) []byte

Returns the next ID in the sequence.

Jump to

Keyboard shortcuts

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