ticket

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 11 Imported by: 0

README

ticketer

Generate new ticket with a uuid based file manager; concurrency safe

random   :0  e4e45937-79c9-c3b4-07e4-7c13d989f9235e15
sequence :1+ 00000001-5d9b-95d2-de8d-9c7cb21451fac9c1

  [4]byte header, uint32 identifier
  [2]byte high 32bit unix time
  [2]byte low 32bit unix time
  [2]byte random uint16
  [8]byte random uint64

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ticket

type Ticket struct {
	Path string // default is /tmp
	// contains filtered or unexported fields
}

Ticket

func NewTicket

func NewTicket(path string) *Ticket

NewTicket is the *Ticket configurator; provides assurance Path exists

func (*Ticket) Expire

func (m *Ticket) Expire(age *time.Duration) *Ticket

Expire aged tickets in ticket.Path now; nil sets default 12hr when not already set or age sets ttl to timeframe specified

func (*Ticket) Generate

func (m *Ticket) Generate() string

Generate new ticket uuid; concurrency safe

random :0 e4e45937-79c9-c3b4-07e4-7c13d989f9235e15 sequence :1+ 00000001-5d9b-95d2-de8d-9c7cb21451fac9c1

[4]byte header, uint32 identifier [2]byte high 32bit unix time [2]byte low 32bit unix time [2]byte random uint16 [8]byte random uint64

func (*Ticket) Load

func (m *Ticket) Load(ticket *string, writer io.Writer) bool

Load retrieves the ticketed file and copies the data to the io.Writer

func (*Ticket) Next

func (m *Ticket) Next(random bool) *string

Next returns the next ticket for processing from m.Path reading in directory order, not necessarily fifo; or random selection mixing

func (*Ticket) Queue

func (m *Ticket) Queue() *Ticket

Queue turns queue sequencer on

func (*Ticket) Reader

func (m *Ticket) Reader(ticket *string) (io.ReadCloser, bool)

Reader opens the ticketed file and returns an io.ReadCloser

func (*Ticket) Remove

func (m *Ticket) Remove(ticket *string) bool

Remove a ticketed file from m.Path

func (*Ticket) Save

func (m *Ticket) Save(ticket *string, reader io.Reader) (string, bool)

Save writes data as a ticketed file from io.Reader

func (*Ticket) Start

func (m *Ticket) Start(ctx context.Context)

Start the ttl ticket expiration manager and immediately call m.Expire(nil) which sets default ttl before entering the ticker loop; aborts when in queue mode

func (*Ticket) Writer

func (m *Ticket) Writer(ticket *string) (io.WriteCloser, bool)

Writer creates the ticketed file and returns an io.WriteCloser

Jump to

Keyboard shortcuts

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