Created
August 15, 2021 14:50
-
-
Save kben19/107cc305f29764eb6de6711d06f257e4 to your computer and use it in GitHub Desktop.
Interface example of retail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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