common

package
v0.0.0-...-a9922b0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package common defines common interfaces and types.

Index

Constants

This section is empty.

Variables

View Source
var ErrorInvalidActivationRequest = errors.New("Invalid activation request ID")

ErrorInvalidActivationRequest ...

View Source
var ErrorInvalidTicket = errors.New("Invalid Ticket")

ErrorInvalidTicket ...

Functions

This section is empty.

Types

type BarCoder

type BarCoder interface {
	SetFormat(enc EncodingFormat)
	Encode(w io.Writer, txt string) error
}

BarCoder can generate bar codes, qr-codes, data matrixes, ...

type Device

type Device struct {
	ID   string
	Role Role
}

Device defines the status of a given device.

type EncodingFormat

type EncodingFormat int

EncodingFormat defines QR, DataMatrix, ...

const (
	QR200x200H EncodingFormat = iota
	QR300x300H
	DM200x200
	DM300x300
)

Encoding formats that are available.

type Mailer

type Mailer interface {
	Pinger
	Send(from, to, obj, txt, html string) error
}

Mailer interface to send emails.

type Pinger

type Pinger interface {
	Ping() error
}

Pinger interface to verify health status.

type Role

type Role int

Role defines the role a device can be granted.

const (
	RoleNone Role = iota // Zero-value, does nothing.
	RoleEntry
	RoleExit
	RoleReview
	RoleAdmin
	RoleSuper
)

Predefined Roles for devices.

func (*Role) String

func (r *Role) String() string

String convert role to string

type Storer

type Storer interface {
	Pinger
	Close() error

	// Device management
	GetRole(deviceID string) Role
	SetRole(deviceID string, role Role)
	UnsetRole(deviceID string)

	// CreateRequestID generates a request ID to activate for a given role.
	CreateRequestID(role Role) (requestID string)
	// Activate using the generated requestID
	// You may implemet it so that activation can only happens within certain timeframe,
	// or only once, or only for a single device, ...
	Activate(deviceID string, requestID string) (Role, error)

	GetTicket(tid string) Ticket
	SaveTicket(t Ticket) error
}

Storer is the minimum required interface for data storage.

type Ticket

type Ticket struct {
	TID    string // Ticket ID
	Holder string // Ticket holder information
	Mail   string // Email to forward the ticket when issued
	Issued bool   // If not issued, ticket is not yet valid.
	From,
	To time.Time // Validity period
	Entries,
	Exits int // Counters
}

Ticket data structure.

func (*Ticket) Valid

func (t *Ticket) Valid() bool

Valid tests ticket validity. Adjust condition as needed.

Jump to

Keyboard shortcuts

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