Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Order ¶
type Order struct { ID string Product string Quantity int Status OrderStatus }
Order is a pure domain object, representing an order managed by our application.
NOTE: this struct has no relationships with any specific storage mechism or database. Each implementation of OrderRepository will have to convert from this struct to data-types appropriate for the storage mechanism.
type OrderRepository ¶
type OrderRepository interface { Save(order *Order) error GetMany() ([]Order, error) GetOne(id string) (*Order, error) }
Output port - defines function calls this module makes to external services in this case, calls related to order storage and persistence
type OrderService ¶
type OrderService interface { CreateOrder(product string, quantity int) (*Order, error) GetOrders() ([]Order, error) GetOrder(id string) (*Order, error) }
Input / driving port - defines the functions exposed by this application to external components Driving adapters should implement this interface to expose this application using a specific protocol
Example - an HTTP adapter would create HTTP endpoints for each function Example - a GRPC adapter would expose a GRPC service with unary RPCs for each function
type OrderServiceImpl ¶
type OrderServiceImpl struct {
// contains filtered or unexported fields
}
This struct implements OrderService using ports for all external component interaction.
Ideally, what is left is pure business logic which is both easily testable, and agnostic of any intrastructure changes made during the lifespan of this project.
func NewOrderService ¶
func NewOrderService(repo OrderRepository) *OrderServiceImpl
func (*OrderServiceImpl) CreateOrder ¶
func (os *OrderServiceImpl) CreateOrder(product string, quantity int) (*Order, error)
func (*OrderServiceImpl) GetOrders ¶
func (os *OrderServiceImpl) GetOrders() ([]Order, error)
type OrderStatus ¶
type OrderStatus string
const ( RECEIVED OrderStatus = "RECEIVED" SHIPPED OrderStatus = "SHIPPED" DELIVERED OrderStatus = "DELIVERED" )