equipment

package
v0.0.0-...-cbab839 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ByName sorts items by name.
	ByName sortBy = (1 << iota)
	// ByDate sorts items by update date.
	ByDate
	// ByPrice sorts items by price.
	ByPrice
	// ByInUse sorts items by use state.
	ByInUse
	// ByInUseDate sorts items by use state first and update date second.
	ByInUseDate
)

Variables

View Source
var (
	// CustomPath sets a custom directory to store the inventory.
	CustomPath string
	// ReturnLocation sets the return location of the inventory (default:
	// returned).
	ReturnLocation = "returned"
)

Functions

func Path

func Path() string

Path returns the path of the inventory.

func Sort

func Sort(element sortBy, items []*Item, reversed bool)

Sort sorts a slice of items by the speciafied element.

Types

type Item

type Item struct {
	ID       string    `yaml:"id"`
	Name     string    `yaml:"name"`
	Price    string    `yaml:"price"`
	Location string    `yaml:"location"`
	Updated  time.Time `yaml:"update"`
	InUse    bool      `yaml:"borrowed"`
}

Item is the item in the inventory.

func Add

func Add(name string) (*Item, error)

Add adds a new named item to the inventory. It will auto-generate a unique ID for the item based on the name.

func Items

func Items() ([]*Item, error)

Items returns the list of items in the inventory.

func SortedItems

func SortedItems(by sortBy, reversed bool) ([]*Item, error)

SortedItems returns a sorted slice of items in the inventory.

func (*Item) LocationPicture

func (i *Item) LocationPicture() (image.Image, error)

LocationPicture returns the picture of the location associated with the item.

func (*Item) Picture

func (i *Item) Picture() (image.Image, error)

Picture returns the picture associated with the item.

func (*Item) SetLocationPicture

func (i *Item) SetLocationPicture(r io.ReadSeeker) error

SetLocationPicture sets the thumbnail picture of the item. To save space, the image is resized within 1000x1000 pixels and encoded as jpeg.

func (*Item) SetPicture

func (i *Item) SetPicture(r io.ReadSeeker) error

SetPicture sets the thumbnail picture of the item. To save space, the image is resized within 1000x1000 pixels and encoded as jpeg.

func (*Item) String

func (i *Item) String() string

String implements the Stringer interface.

func (*Item) Update

func (i *Item) Update() error

Update updates the information of the item on disk.

func (*Item) Use

func (i *Item) Use(who string) error

Use sets who is currently using the item and updates the information on disk. If the return code `retCODE` is passed, the item is set as returned to the `ReturnLocation`.

Jump to

Keyboard shortcuts

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