database

package
v0.0.0-...-83a9ce1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Normal indicates that the device is operating in light output mode.
	Normal = iota
	// Vote indicates that the device is currently in a voting mode.
	Vote
)

Variables

This section is empty.

Functions

func GetName

func GetName(c Controller) string

GetName gets the default bucket name (or tableName) of the given struct.

Types

type BridgePayload

type BridgePayload struct {
	ID            uint8    `json:"id"`
	Mode          Mode     `json:"mode"`
	ColorSequence []uint32 `json:"colorsequence"`
}

BridgePayload contains the information required by the bridge to send to each of the bands.

type Color

type Color struct {
	ID       uint8    `json:"id"`
	Name     string   `json:"name"`
	Sequence []uint32 `json:"sequence"`
}

Color contains color information for the bands.

func (*Color) MarshalJSON

func (c *Color) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON interface for Color.

func (*Color) UnmarshalJSON

func (c *Color) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the JSON interface for Color.

type ColorController

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

ColorController is a struct containing information on the Colors bucket.

func (*ColorController) Add

func (cc *ColorController) Add(db *bolt.DB, color []byte) error

Add method adds a single color to the database.

func (*ColorController) AddMultiple

func (cc *ColorController) AddMultiple(db *bolt.DB, colors []byte) error

AddMultiple adds multiple color sequences to the database.

func (*ColorController) Get

func (cc *ColorController) Get(db *bolt.DB, identifier interface{}) (interface{}, error)

Get gets a single Color from the database based on given ID.

func (*ColorController) GetAll

func (cc *ColorController) GetAll(db *bolt.DB) ([]interface{}, error)

GetAll method gets a list of all color sequences from the database.

func (*ColorController) Initialize

func (cc *ColorController) Initialize(db *bolt.DB) error

Initialize creates the Colors bucket required for this controller.

type Controller

type Controller interface {
	Initialize(*bolt.DB) error

	// Generic get methods.
	Get(*bolt.DB, interface{}) (interface{}, error)
	GetAll(*bolt.DB) ([]interface{}, error)

	// Generic add/update methods
	Add(*bolt.DB, []byte) error
	AddMultiple(*bolt.DB, []byte) error
}

Controller interface provides a list of methods that a controller should implement.

type DBHandler

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

DBHandler acts as an interface for bbolt.

func New

func New(path string) DBHandler

New creates a new handler interface for bbolt.

func (*DBHandler) Add

func (h *DBHandler) Add(controller string, singleton []byte) error

Add runs the Add interface method on the controller with the given name.

func (*DBHandler) AddMultiple

func (h *DBHandler) AddMultiple(controller string, set []byte) error

AddMultiple runs the AddMultiple interface method on the controller with the given name.

func (*DBHandler) CreatePayload

func (h *DBHandler) CreatePayload(devices []Device) []BridgePayload

CreatePayload creates a communication payload for the bridge.

func (*DBHandler) Get

func (h *DBHandler) Get(controller string, id interface{}) (interface{}, error)

Get runs the Get interface method on the controller with the given name.

func (*DBHandler) GetAll

func (h *DBHandler) GetAll(controller string) ([]interface{}, error)

GetAll runs the GetAll interface method on the controller with the given name.

type Device

type Device struct {
	ID          uint8 `json:"id"`
	Mode        Mode  `json:"mode"`
	ColorScheme uint8 `json:"color"`
}

Device contains device-specific information about individual bands.

func (*Device) MarshalJSON

func (d *Device) MarshalJSON() ([]byte, error)

MarshalJSON is the interface method for json.Marshall for the Device struct.

func (*Device) UnmarshalJSON

func (d *Device) UnmarshalJSON(b []byte) error

UnmarshalJSON is the interface method for json.Unmarshal for the Device struct. This method also provides some validation.

type DeviceController

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

DeviceController is a struct containing bucket information as well as required interface methods.

func (*DeviceController) Add

func (dc *DeviceController) Add(db *bolt.DB, dev []byte) error

Add method adds a single device based on the inputs from a JSON byte stream.

func (*DeviceController) AddMultiple

func (dc *DeviceController) AddMultiple(db *bolt.DB, devs []byte) error

AddMultiple method adds multiple devices from a JSON byte stream.

func (*DeviceController) Get

func (dc *DeviceController) Get(db *bolt.DB, identifier interface{}) (interface{}, error)

Get method gets a single device from the Devices bucket that matches the passed integer ID.

func (*DeviceController) GetAll

func (dc *DeviceController) GetAll(db *bolt.DB) ([]interface{}, error)

GetAll method gets a list of all devices.

func (*DeviceController) Initialize

func (dc *DeviceController) Initialize(db *bolt.DB) error

Initialize creates the bucket required for the "Devices" controller.

type Mode

type Mode int

Mode enumerates device modes.

type VoteController

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

VoteController is a struct containing information on the Votes bucket.

func (*VoteController) Add

func (vc *VoteController) Add(db *bolt.DB, votes []byte) error

Add method updates the vote count from the input of a JSON byte stream.

func (VoteController) AddMultiple

func (vc VoteController) AddMultiple(db *bolt.DB, votes []byte) error

AddMultiple is an alias for the Add method.

func (*VoteController) Get

func (vc *VoteController) Get(db *bolt.DB, _ interface{}) (interface{}, error)

Get method gets all of the votes from the database.

func (VoteController) GetAll

func (vc VoteController) GetAll(db *bolt.DB) ([]interface{}, error)

GetAll method is an alias for Get method except the output is packaged into a slice.

func (*VoteController) Initialize

func (vc *VoteController) Initialize(db *bolt.DB) error

Initialize sets the fields of the passed VoteController and create the required bucket.

type VoteResult

type VoteResult struct {
	Positive int `json:"positive"`
	Negative int `json:"negative"`
}

VoteResult contains the results from voting in the database.

Jump to

Keyboard shortcuts

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