Skip to content

Instantly share code, notes, and snippets.

@kben19
Created August 15, 2021 14:50
Show Gist options
  • Save kben19/107cc305f29764eb6de6711d06f257e4 to your computer and use it in GitHub Desktop.
Save kben19/107cc305f29764eb6de6711d06f257e4 to your computer and use it in GitHub Desktop.
Interface example of retail
type WarehouseItf interface {
GetProduct(id int) (Product, error)
InsertProduct(product Product) error
}
type Retail struct {
warehouse WarehouseItf
}
func (retail *Retail) GetMyProduct() ([]Product, error) {
aProduct, err := retail.warehouse.GetProduct(1)
if err != nil {
return nil, err
}
return []Product{aProduct}, nil
}
func New(warehouse WarehouseItf) *Retail {
return &Retail{warehouse}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment