Documentation ¶
Index ¶
- Variables
- func WithConsumablesOption(opts ...resource.Option) resource.Option
- func WithInitialConsumable(consumables ...*traits.Consumable) resource.Option
- func WithInitialStock(inventory ...*traits.Consumable_Stock) resource.Option
- func WithInventoryOption(opts ...resource.Option) resource.Option
- func WithVendingApiClientFactory(f func(name string) (traits.VendingApiClient, error)) router.Option
- func WithVendingInfoClientFactory(f func(name string) (traits.VendingInfoClient, error)) router.Option
- type ApiRouter
- func (r *ApiRouter) Add(name string, client any) any
- func (r *ApiRouter) AddVendingApiClient(name string, client traits.VendingApiClient) traits.VendingApiClient
- func (r *ApiRouter) Dispense(ctx context.Context, request *traits.DispenseRequest) (*traits.Consumable_Stock, error)
- func (r *ApiRouter) GetStock(ctx context.Context, request *traits.GetStockRequest) (*traits.Consumable_Stock, error)
- func (r *ApiRouter) GetVendingApiClient(name string) (traits.VendingApiClient, error)
- func (r *ApiRouter) HoldsType(client any) bool
- func (r *ApiRouter) ListConsumables(ctx context.Context, request *traits.ListConsumablesRequest) (*traits.ListConsumablesResponse, error)
- func (r *ApiRouter) ListInventory(ctx context.Context, request *traits.ListInventoryRequest) (*traits.ListInventoryResponse, error)
- func (r *ApiRouter) PullConsumables(request *traits.PullConsumablesRequest, ...) error
- func (r *ApiRouter) PullInventory(request *traits.PullInventoryRequest, ...) error
- func (r *ApiRouter) PullStock(request *traits.PullStockRequest, server traits.VendingApi_PullStockServer) error
- func (r *ApiRouter) Register(server grpc.ServiceRegistrar)
- func (r *ApiRouter) RemoveVendingApiClient(name string) traits.VendingApiClient
- func (r *ApiRouter) StopDispense(ctx context.Context, request *traits.StopDispenseRequest) (*traits.Consumable_Stock, error)
- func (r *ApiRouter) UpdateStock(ctx context.Context, request *traits.UpdateStockRequest) (*traits.Consumable_Stock, error)
- type ApiWrapper
- type ConsumableChange
- type ConsumablesChange
- type InfoRouter
- func (r *InfoRouter) Add(name string, client any) any
- func (r *InfoRouter) AddVendingInfoClient(name string, client traits.VendingInfoClient) traits.VendingInfoClient
- func (r *InfoRouter) GetVendingInfoClient(name string) (traits.VendingInfoClient, error)
- func (r *InfoRouter) HoldsType(client any) bool
- func (r *InfoRouter) Register(server grpc.ServiceRegistrar)
- func (r *InfoRouter) RemoveVendingInfoClient(name string) traits.VendingInfoClient
- type InfoWrapper
- type InventoryChange
- type Model
- func (m *Model) CreateConsumable(consumable *traits.Consumable) (*traits.Consumable, error)
- func (m *Model) CreateStock(stock *traits.Consumable_Stock) (*traits.Consumable_Stock, error)
- func (m *Model) DeleteConsumable(name string, opts ...resource.WriteOption) (*traits.Consumable, error)
- func (m *Model) DeleteStock(consumable string, opts ...resource.WriteOption) (*traits.Consumable_Stock, error)
- func (m *Model) DispenseInstantly(consumable string, quantity *traits.Consumable_Quantity) (*traits.Consumable_Stock, error)
- func (m *Model) GetConsumable(name string, opts ...resource.ReadOption) (*traits.Consumable, bool)
- func (m *Model) GetStock(consumable string, opts ...resource.ReadOption) (*traits.Consumable_Stock, bool)
- func (m *Model) ListConsumables(opts ...resource.ReadOption) []*traits.Consumable
- func (m *Model) ListInventory(opts ...resource.ReadOption) []*traits.Consumable_Stock
- func (m *Model) PullConsumable(ctx context.Context, name string, opts ...resource.ReadOption) <-chan ConsumableChange
- func (m *Model) PullConsumables(ctx context.Context, opts ...resource.ReadOption) <-chan ConsumablesChange
- func (m *Model) PullInventory(ctx context.Context, opts ...resource.ReadOption) <-chan InventoryChange
- func (m *Model) PullStock(ctx context.Context, consumable string, opts ...resource.ReadOption) <-chan StockChange
- func (m *Model) UpdateConsumable(consumable *traits.Consumable, opts ...resource.WriteOption) (*traits.Consumable, error)
- func (m *Model) UpdateStock(stock *traits.Consumable_Stock, opts ...resource.WriteOption) (*traits.Consumable_Stock, error)
- type ModelOption
- type ModelServer
- func (m *ModelServer) Dispense(_ context.Context, request *traits.DispenseRequest) (*traits.Consumable_Stock, error)
- func (m *ModelServer) GetStock(_ context.Context, request *traits.GetStockRequest) (*traits.Consumable_Stock, error)
- func (m *ModelServer) ListConsumables(_ context.Context, request *traits.ListConsumablesRequest) (*traits.ListConsumablesResponse, error)
- func (m *ModelServer) ListInventory(_ context.Context, request *traits.ListInventoryRequest) (*traits.ListInventoryResponse, error)
- func (m *ModelServer) PullConsumables(request *traits.PullConsumablesRequest, ...) error
- func (m *ModelServer) PullInventory(request *traits.PullInventoryRequest, ...) error
- func (m *ModelServer) PullStock(request *traits.PullStockRequest, server traits.VendingApi_PullStockServer) error
- func (m *ModelServer) Register(server grpc.ServiceRegistrar)
- func (m *ModelServer) StopDispense(ctx context.Context, request *traits.StopDispenseRequest) (*traits.Consumable_Stock, error)
- func (m *ModelServer) Unwrap() any
- func (m *ModelServer) UpdateStock(_ context.Context, request *traits.UpdateStockRequest) (*traits.Consumable_Stock, error)
- type StockChange
Constants ¶
This section is empty.
Variables ¶
var DefaultModelOptions []resource.Option
DefaultModelOptions holds the default options for the model.
Functions ¶
func WithConsumablesOption ¶
WithConsumablesOption configures the consumables resource of the model.
func WithInitialConsumable ¶
func WithInitialConsumable(consumables ...*traits.Consumable) resource.Option
WithInitialConsumable configures the model to initialise with the given consumable. Can be used multiple times with consumables being additive. Creating a model with duplicate consumable names will panic. Calling this function with an empty consumable name property will panic.
func WithInitialStock ¶
func WithInitialStock(inventory ...*traits.Consumable_Stock) resource.Option
WithInitialStock configures the model to initialise with the given stock. Can be used multiple times with stock being additive. Creating a model with duplicate stock consumable names will panic. Calling this function with an empty stock consumable property will panic.
func WithInventoryOption ¶
WithInventoryOption configures the inventory resource of the model.
func WithVendingApiClientFactory ¶
func WithVendingApiClientFactory(f func(name string) (traits.VendingApiClient, error)) router.Option
WithVendingApiClientFactory instructs the router to create a new client the first time Get is called for that name.
func WithVendingInfoClientFactory ¶
func WithVendingInfoClientFactory(f func(name string) (traits.VendingInfoClient, error)) router.Option
WithVendingInfoClientFactory instructs the router to create a new client the first time Get is called for that name.
Types ¶
type ApiRouter ¶
type ApiRouter struct { traits.UnimplementedVendingApiServer router.Router }
ApiRouter is a traits.VendingApiServer that allows routing named requests to specific traits.VendingApiClient
func NewApiRouter ¶
func (*ApiRouter) Add ¶
Add extends Router.Add to panic if client is not of type traits.VendingApiClient.
func (*ApiRouter) AddVendingApiClient ¶
func (r *ApiRouter) AddVendingApiClient(name string, client traits.VendingApiClient) traits.VendingApiClient
func (*ApiRouter) Dispense ¶
func (r *ApiRouter) Dispense(ctx context.Context, request *traits.DispenseRequest) (*traits.Consumable_Stock, error)
func (*ApiRouter) GetStock ¶
func (r *ApiRouter) GetStock(ctx context.Context, request *traits.GetStockRequest) (*traits.Consumable_Stock, error)
func (*ApiRouter) GetVendingApiClient ¶
func (r *ApiRouter) GetVendingApiClient(name string) (traits.VendingApiClient, error)
func (*ApiRouter) ListConsumables ¶
func (r *ApiRouter) ListConsumables(ctx context.Context, request *traits.ListConsumablesRequest) (*traits.ListConsumablesResponse, error)
func (*ApiRouter) ListInventory ¶
func (r *ApiRouter) ListInventory(ctx context.Context, request *traits.ListInventoryRequest) (*traits.ListInventoryResponse, error)
func (*ApiRouter) PullConsumables ¶
func (r *ApiRouter) PullConsumables(request *traits.PullConsumablesRequest, server traits.VendingApi_PullConsumablesServer) error
func (*ApiRouter) PullInventory ¶
func (r *ApiRouter) PullInventory(request *traits.PullInventoryRequest, server traits.VendingApi_PullInventoryServer) error
func (*ApiRouter) PullStock ¶
func (r *ApiRouter) PullStock(request *traits.PullStockRequest, server traits.VendingApi_PullStockServer) error
func (*ApiRouter) Register ¶
func (r *ApiRouter) Register(server grpc.ServiceRegistrar)
func (*ApiRouter) RemoveVendingApiClient ¶
func (r *ApiRouter) RemoveVendingApiClient(name string) traits.VendingApiClient
func (*ApiRouter) StopDispense ¶
func (r *ApiRouter) StopDispense(ctx context.Context, request *traits.StopDispenseRequest) (*traits.Consumable_Stock, error)
func (*ApiRouter) UpdateStock ¶
func (r *ApiRouter) UpdateStock(ctx context.Context, request *traits.UpdateStockRequest) (*traits.Consumable_Stock, error)
type ApiWrapper ¶
type ApiWrapper struct { traits.VendingApiClient // contains filtered or unexported fields }
func WrapApi ¶
func WrapApi(server traits.VendingApiServer) *ApiWrapper
WrapApi adapts a traits.VendingApiServer and presents it as a traits.VendingApiClient
func (*ApiWrapper) Unwrap ¶
func (w *ApiWrapper) Unwrap() any
Unwrap implements wrap.Unwrapper and returns the underlying server instance as an unknown type.
func (*ApiWrapper) UnwrapServer ¶
func (w *ApiWrapper) UnwrapServer() traits.VendingApiServer
UnwrapServer returns the underlying server instance.
func (*ApiWrapper) UnwrapService ¶
func (w *ApiWrapper) UnwrapService() (grpc.ClientConnInterface, grpc.ServiceDesc)
type ConsumableChange ¶
type ConsumableChange struct { ChangeTime time.Time Value *traits.Consumable }
type ConsumablesChange ¶
type ConsumablesChange struct { ID string ChangeTime time.Time ChangeType types.ChangeType OldValue *traits.Consumable NewValue *traits.Consumable }
type InfoRouter ¶
type InfoRouter struct { traits.UnimplementedVendingInfoServer router.Router }
InfoRouter is a traits.VendingInfoServer that allows routing named requests to specific traits.VendingInfoClient
func NewInfoRouter ¶
func NewInfoRouter(opts ...router.Option) *InfoRouter
func (*InfoRouter) Add ¶
func (r *InfoRouter) Add(name string, client any) any
Add extends Router.Add to panic if client is not of type traits.VendingInfoClient.
func (*InfoRouter) AddVendingInfoClient ¶
func (r *InfoRouter) AddVendingInfoClient(name string, client traits.VendingInfoClient) traits.VendingInfoClient
func (*InfoRouter) GetVendingInfoClient ¶
func (r *InfoRouter) GetVendingInfoClient(name string) (traits.VendingInfoClient, error)
func (*InfoRouter) HoldsType ¶
func (r *InfoRouter) HoldsType(client any) bool
func (*InfoRouter) Register ¶
func (r *InfoRouter) Register(server grpc.ServiceRegistrar)
func (*InfoRouter) RemoveVendingInfoClient ¶
func (r *InfoRouter) RemoveVendingInfoClient(name string) traits.VendingInfoClient
type InfoWrapper ¶
type InfoWrapper struct { traits.VendingInfoClient // contains filtered or unexported fields }
func WrapInfo ¶
func WrapInfo(server traits.VendingInfoServer) *InfoWrapper
WrapInfo adapts a traits.VendingInfoServer and presents it as a traits.VendingInfoClient
func (*InfoWrapper) Unwrap ¶
func (w *InfoWrapper) Unwrap() any
Unwrap implements wrap.Unwrapper and returns the underlying server instance as an unknown type.
func (*InfoWrapper) UnwrapServer ¶
func (w *InfoWrapper) UnwrapServer() traits.VendingInfoServer
UnwrapServer returns the underlying server instance.
func (*InfoWrapper) UnwrapService ¶
func (w *InfoWrapper) UnwrapService() (grpc.ClientConnInterface, grpc.ServiceDesc)
type InventoryChange ¶
type InventoryChange struct { ID string ChangeTime time.Time ChangeType types.ChangeType OldValue *traits.Consumable_Stock NewValue *traits.Consumable_Stock }
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model describes the data structure needed to implement the Vending trait.
func NewModel ¶
NewModel creates a new Model with the given options. Options from the resource package are applied to all resources of this model. Use WithInventoryOption or WithConsumablesOption to target a specific resource. See WithInitialStock and WithInitialConsumable for simple ways to pre-populate this model.
func (*Model) CreateConsumable ¶
func (m *Model) CreateConsumable(consumable *traits.Consumable) (*traits.Consumable, error)
CreateConsumable creates a new consumable record. If consumable.Name is specified it will be used as the key, it absent a new name will be invented. If the consumables name already exists, an error will be returned.
func (*Model) CreateStock ¶
func (m *Model) CreateStock(stock *traits.Consumable_Stock) (*traits.Consumable_Stock, error)
CreateStock adds a stock record to this model. If stock.Consumable is not supplied, a new consumable name will be invented. Errors if the stock.Consumable already exists as a known stock entry.
func (*Model) DeleteConsumable ¶
func (m *Model) DeleteConsumable(name string, opts ...resource.WriteOption) (*traits.Consumable, error)
func (*Model) DeleteStock ¶
func (m *Model) DeleteStock(consumable string, opts ...resource.WriteOption) (*traits.Consumable_Stock, error)
func (*Model) DispenseInstantly ¶
func (m *Model) DispenseInstantly(consumable string, quantity *traits.Consumable_Quantity) (*traits.Consumable_Stock, error)
DispenseInstantly removes quantity amount from the stock of the named consumable. This updates the stock LastDispensed, Used, and Remaining. Used and Remaining are only updated if they have a (possibly zero) value in the stock already. Stock Used and Remaining units are maintained, the quantity is converted to those units before modification.
func (*Model) GetConsumable ¶
func (m *Model) GetConsumable(name string, opts ...resource.ReadOption) (*traits.Consumable, bool)
func (*Model) GetStock ¶
func (m *Model) GetStock(consumable string, opts ...resource.ReadOption) (*traits.Consumable_Stock, bool)
func (*Model) ListConsumables ¶
func (m *Model) ListConsumables(opts ...resource.ReadOption) []*traits.Consumable
func (*Model) ListInventory ¶
func (m *Model) ListInventory(opts ...resource.ReadOption) []*traits.Consumable_Stock
ListInventory returns all known stock records.
func (*Model) PullConsumable ¶
func (m *Model) PullConsumable(ctx context.Context, name string, opts ...resource.ReadOption) <-chan ConsumableChange
func (*Model) PullConsumables ¶
func (m *Model) PullConsumables(ctx context.Context, opts ...resource.ReadOption) <-chan ConsumablesChange
func (*Model) PullInventory ¶
func (m *Model) PullInventory(ctx context.Context, opts ...resource.ReadOption) <-chan InventoryChange
PullInventory subscribes to changes in the list of known stock records.
func (*Model) PullStock ¶
func (m *Model) PullStock(ctx context.Context, consumable string, opts ...resource.ReadOption) <-chan StockChange
PullStock subscribes to changes in a single consumables stock. The returned channel will be closed if ctx is Done or the stock record identified by consumable is deleted.
func (*Model) UpdateConsumable ¶
func (m *Model) UpdateConsumable(consumable *traits.Consumable, opts ...resource.WriteOption) (*traits.Consumable, error)
func (*Model) UpdateStock ¶
func (m *Model) UpdateStock(stock *traits.Consumable_Stock, opts ...resource.WriteOption) (*traits.Consumable_Stock, error)
type ModelOption ¶
ModelOption defined the base type for all options that apply to this traits model.
type ModelServer ¶
type ModelServer struct { traits.UnimplementedVendingApiServer // contains filtered or unexported fields }
ModelServer adapts a Model to implement traits.VendingApiServer.
func NewModelServer ¶
func NewModelServer(model *Model) *ModelServer
func (*ModelServer) Dispense ¶
func (m *ModelServer) Dispense(_ context.Context, request *traits.DispenseRequest) (*traits.Consumable_Stock, error)
func (*ModelServer) GetStock ¶
func (m *ModelServer) GetStock(_ context.Context, request *traits.GetStockRequest) (*traits.Consumable_Stock, error)
func (*ModelServer) ListConsumables ¶
func (m *ModelServer) ListConsumables(_ context.Context, request *traits.ListConsumablesRequest) (*traits.ListConsumablesResponse, error)
func (*ModelServer) ListInventory ¶
func (m *ModelServer) ListInventory(_ context.Context, request *traits.ListInventoryRequest) (*traits.ListInventoryResponse, error)
func (*ModelServer) PullConsumables ¶
func (m *ModelServer) PullConsumables(request *traits.PullConsumablesRequest, server traits.VendingApi_PullConsumablesServer) error
func (*ModelServer) PullInventory ¶
func (m *ModelServer) PullInventory(request *traits.PullInventoryRequest, server traits.VendingApi_PullInventoryServer) error
func (*ModelServer) PullStock ¶
func (m *ModelServer) PullStock(request *traits.PullStockRequest, server traits.VendingApi_PullStockServer) error
func (*ModelServer) Register ¶
func (m *ModelServer) Register(server grpc.ServiceRegistrar)
func (*ModelServer) StopDispense ¶
func (m *ModelServer) StopDispense(ctx context.Context, request *traits.StopDispenseRequest) (*traits.Consumable_Stock, error)
func (*ModelServer) Unwrap ¶
func (m *ModelServer) Unwrap() any
func (*ModelServer) UpdateStock ¶
func (m *ModelServer) UpdateStock(_ context.Context, request *traits.UpdateStockRequest) (*traits.Consumable_Stock, error)
type StockChange ¶
type StockChange struct { ChangeTime time.Time Value *traits.Consumable_Stock }