Documentation
¶
Index ¶
- Constants
- type Product
- type ProductInterface
- type ProductPersistenceInterface
- type ProductReader
- type ProductService
- func (s *ProductService) Create(name string, price float64) (ProductInterface, error)
- func (s *ProductService) Disable(product ProductInterface) (ProductInterface, error)
- func (s *ProductService) Enable(product ProductInterface) (ProductInterface, error)
- func (s *ProductService) Get(id string) (ProductInterface, error)
- type ProductServiceInterface
- type ProductWriter
Constants ¶
View Source
const ( DISABLED = "disabled" ENABLED = "enabled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Product ¶
type ProductInterface ¶
type ProductPersistenceInterface ¶
type ProductPersistenceInterface interface { ProductReader ProductWriter }
Defining a single interface for DB operations with interface composition Any DB that is implemented will never communicate with the Service directly
type ProductReader ¶
type ProductReader interface {
Get(id string) (ProductInterface, error)
}
Interface for Reading DB
type ProductService ¶
type ProductService struct {
Persistence ProductPersistenceInterface
}
func NewProductService ¶
func NewProductService(persistence ProductPersistenceInterface) *ProductService
func (*ProductService) Create ¶
func (s *ProductService) Create(name string, price float64) (ProductInterface, error)
func (*ProductService) Disable ¶
func (s *ProductService) Disable(product ProductInterface) (ProductInterface, error)
func (*ProductService) Enable ¶
func (s *ProductService) Enable(product ProductInterface) (ProductInterface, error)
func (*ProductService) Get ¶
func (s *ProductService) Get(id string) (ProductInterface, error)
type ProductServiceInterface ¶
type ProductServiceInterface interface { Get(id string) (ProductInterface, error) Create(name string, price float64) (ProductInterface, error) Enable(product ProductInterface) (ProductInterface, error) Disable(product ProductInterface) (ProductInterface, error) }
Technical details such as DB persistence are not defined here The Service Interface is decoupled from specific implementations This is a crucial point on Hexagonal Architecture
type ProductWriter ¶
type ProductWriter interface {
Save(product ProductInterface) (ProductInterface, error)
}
Interface for Saving on DB
Click to show internal directories.
Click to hide internal directories.