ticket

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BoltDBFile = "tickets.db"

BoltDBFile is the filename to store the boltdb database

View Source
const BucketName = "tickets"

BucketName is the bucket name to store the tickets on the bolt db

View Source
const TicketHeader = "x-bitmaelum-ticket"

TicketHeader is the HTTP Header that contains our ticket ID when sending messages

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	Fetch(ticketID string) (*Ticket, error)
	Store(ticket *Ticket) error
	Remove(ticketID string)
}

Repository is a ticket repository to fetch and store tickets

func NewBoltRepository

func NewBoltRepository(dbpath string) Repository

NewBoltRepository initializes a new repository

func NewRedisRepository

func NewRedisRepository(opts *redis.Options) Repository

NewRedisRepository initializes a new repository

type Ticket

type Ticket struct {
	ID     string    // ticket ID
	Valid  bool      // true if the ticket is valid
	Expiry time.Time // Time when this ticket expires
	Work   *WorkType // Work that needs to be done for validating the ticket

	Sender         hash.Hash // From address for this ticket
	Recipient      hash.Hash // To address for this ticket
	SubscriptionID string    // mailing list subscription ID (if any)

	AuthKey string // Optional authkey attached to the ticket in case its send on behalf
}

Ticket is a structure that defines if a client or server is allowed to upload a message, or if additional work has to be done first

func New

func New(senderHash, recipientHash hash.Hash, subscriptionID string) *Ticket

New creates a new unvalidated ticket without work

func NewFromBytes

func NewFromBytes(data []byte) (*Ticket, error)

NewFromBytes will generate a ticket from the json-encoded data

func (*Ticket) Expired

func (t *Ticket) Expired() bool

Expired will return true when the ticket has expired

func (*Ticket) MarshalBinary

func (t *Ticket) MarshalBinary() (data []byte, err error)

MarshalBinary converts a ticket to binary format so it can be stored in Redis

func (*Ticket) UnmarshalBinary

func (t *Ticket) UnmarshalBinary(data []byte) error

UnmarshalBinary converts binary to a ticket so it can be fetched from Redis

type WorkType

type WorkType struct {
	Type string          // Type of work
	Data work.Repository // Work stored on this ticket
}

WorkType is a structure that holds the type and work repository data

func (*WorkType) UnmarshalJSON

func (twt *WorkType) UnmarshalJSON(data []byte) error

UnmarshalJSON We unmarshal from the ticketWorkType, as we do not know which repository implementation we need. However, we can marshal from the implementation. This is why there is no MarshalJSON present here.

Jump to

Keyboard shortcuts

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