Documentation
¶
Index ¶
- Variables
- func InventoryRouter(s InventoryServer) http.HandlerFunc
- func LoadCSV(ds Datastore, data string) error
- func LoadSeedData(ds Datastore) error
- type Datastore
- type Inventory
- type InventoryAdjustment
- type InventoryServer
- type MemoryInventoryStore
- func (m *MemoryInventoryStore) ConditionallyUpdateInventory(prev Inventory, new Inventory) error
- func (m *MemoryInventoryStore) GetAllProductIDs() []int
- func (m *MemoryInventoryStore) GetInventoryByID(id int) (Inventory, error)
- func (m *MemoryInventoryStore) GetProductByID(id int) (Product, error)
- func (m *MemoryInventoryStore) InsertInventory(inventory Inventory) error
- func (m *MemoryInventoryStore) InsertProduct(product Product) error
- func (m *MemoryInventoryStore) UpdateProduct(product Product) error
- type MyInventoryServer
- func (m *MyInventoryServer) HandleCreateInventory(w http.ResponseWriter, r *http.Request)
- func (m *MyInventoryServer) HandleGetInventories(w http.ResponseWriter, r *http.Request)
- func (m *MyInventoryServer) HandleGetInventory(w http.ResponseWriter, r *http.Request)
- func (m *MyInventoryServer) HandleUpdateInventory(w http.ResponseWriter, r *http.Request)
- type Product
- type ProductInventory
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInsertFailed = errors.New("insert failed")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUpdateFailed = errors.New("udpate failed")
Functions ¶
func InventoryRouter ¶
func InventoryRouter(s InventoryServer) http.HandlerFunc
func LoadSeedData ¶
Types ¶
type Datastore ¶
type Datastore interface { GetAllProductIDs() []int GetProductByID(int) (Product, error) GetInventoryByID(int) (Inventory, error) InsertProduct(Product) error UpdateProduct(Product) error InsertInventory(Inventory) error // ConditionallyUpdateInventory performs a compare-and-set operation, updating the inventory only if the current // value for the given item matches the supplied prev value. This is to prevent concurrent read-modify-write // operations from overwriting each other. Proper usage: // prev := ds.GetInventoryById(id) // updated := prev // updated.Inventory = prev.Inventory + 10 // ds.ConditionallyUpdateInventory(prev, updated) ConditionallyUpdateInventory(prev Inventory, new Inventory) error }
type InventoryAdjustment ¶
type InventoryAdjustment struct {
Adjustment int `json:"inventory_adjustment"`
}
type InventoryServer ¶
type InventoryServer interface { HandleGetInventories(w http.ResponseWriter, r *http.Request) HandleGetInventory(w http.ResponseWriter, r *http.Request) HandleCreateInventory(w http.ResponseWriter, r *http.Request) HandleUpdateInventory(w http.ResponseWriter, r *http.Request) }
type MemoryInventoryStore ¶
type MemoryInventoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryDatastore ¶
func NewMemoryDatastore() *MemoryInventoryStore
func (*MemoryInventoryStore) ConditionallyUpdateInventory ¶
func (m *MemoryInventoryStore) ConditionallyUpdateInventory(prev Inventory, new Inventory) error
func (*MemoryInventoryStore) GetAllProductIDs ¶
func (m *MemoryInventoryStore) GetAllProductIDs() []int
func (*MemoryInventoryStore) GetInventoryByID ¶
func (m *MemoryInventoryStore) GetInventoryByID(id int) (Inventory, error)
func (*MemoryInventoryStore) GetProductByID ¶
func (m *MemoryInventoryStore) GetProductByID(id int) (Product, error)
func (*MemoryInventoryStore) InsertInventory ¶
func (m *MemoryInventoryStore) InsertInventory(inventory Inventory) error
func (*MemoryInventoryStore) InsertProduct ¶
func (m *MemoryInventoryStore) InsertProduct(product Product) error
func (*MemoryInventoryStore) UpdateProduct ¶
func (m *MemoryInventoryStore) UpdateProduct(product Product) error
type MyInventoryServer ¶
type MyInventoryServer struct {
// contains filtered or unexported fields
}
func (*MyInventoryServer) HandleCreateInventory ¶
func (m *MyInventoryServer) HandleCreateInventory(w http.ResponseWriter, r *http.Request)
HandleCreateInventory should handle PUT /inventories/{product_id} requests
func (*MyInventoryServer) HandleGetInventories ¶
func (m *MyInventoryServer) HandleGetInventories(w http.ResponseWriter, r *http.Request)
HandleGetInventories should handle GET /inventories requests
func (*MyInventoryServer) HandleGetInventory ¶
func (m *MyInventoryServer) HandleGetInventory(w http.ResponseWriter, r *http.Request)
HandleGetInventory should handle GET /inventory/{product_id} requests
func (*MyInventoryServer) HandleUpdateInventory ¶
func (m *MyInventoryServer) HandleUpdateInventory(w http.ResponseWriter, r *http.Request)
HandleUpdateInventory should handle POST /inventories/{product_id} requests
Click to show internal directories.
Click to hide internal directories.