inventory

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 18 Imported by: 0

README

Inventory

Version PkgGoDev License Go version

Inventory is an inventory manager written in Go and served as a web page. It was developed to keep track of items in a small scale, like research laboratories or homes.

How does it work?

By default, inventory will run a web server at localhost:8080 and create a directory at $HOME/.inventory to store the information of each item.

You can change the port and directory by passing:

$ inventory -p 5005 -d /path/to/inventory/dir

localhost:8080 shows a table with the list of items in the inventory. You can press + Add item to add a new item to the inventory using the web interface or manually create an entry at $HOME/.inventory.

Items

Each item is added to its own directory with a unique id name and consist of a info.yaml metadata file, picture.jpg with a picture of the item, and location.jpg with a photo of the return location.

Once the item is added, it will appear inside the table at the root url. Clicking on the thumbnail of the item will open a new page with a QR code linking that specific item. You can print this QR code and physically attach it to the item.

Check in/out with QR codes

Scanning the QR code will open an update item interface where the user is prompted to write their name. Clicking on Use item! will change the state of the item to in use = true and show the name of the person using the item.

After finishing using the item, scan the QR code again to return the item. This time, the user is prompted to upload a photo of the place the item was returned at. Pressing on Return item! will change the state of the item to in use = false and the location of the item can be reviewed by clicking on the returned link from the main inventory url.

Security

If only restricted users should have access to the inventory, then create a .htdigest file or .htpasswd file and add users to the realm inventory.

Then, run inventory as:

$ inventory -c /path/to/.htdigest

This will block the access to the inventory main page, but the QR scan can still be accessed by anyone.

Installation

You can download the release binaries or compile it from source by running:

$ go get -v github.com/cgxeiji/inventory/inventory

Documentation

Index

Constants

View Source
const (
	// ByName sorts items by name.
	ByName sortBy = (1 << iota)
	// ByDate sorts items by update date.
	ByDate
	// 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"`
	Location string    `yaml:"location"`
	Updated  time.Time `yaml:"update"`
	InUse    bool      `yaml:"borrowred"`
}

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