Skip to content

Instantly share code, notes, and snippets.

@liampulles
Created April 18, 2022 10:18
Show Gist options
  • Save liampulles/dfc95496fdc6d82f489abc96e4736ad2 to your computer and use it in GitHub Desktop.
Save liampulles/dfc95496fdc6d82f489abc96e4736ad2 to your computer and use it in GitHub Desktop.
// IsAvailable will return true if the inventory item may
// be checked out - false otherwise.
func (i *InventoryItemImpl) IsAvailable() bool {
return i.available
}
// Checkout will mark the inventory item as unavilable.
// If the inventory item is not available,
// then an error is returned.
func (i *InventoryItemImpl) Checkout() error {
if !i.available {
return fmt.Errorf("cannot check out inventory item - it is unavailable")
}
i.available = false
return nil
}
// CheckIn will mark the inventory item as available.
// If the inventory item is available, then an
// error is returned.
func (i *InventoryItemImpl) CheckIn() error {
if i.available {
return fmt.Errorf("cannot check in inventory item - it is already checked in")
}
i.available = true
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment