Adding Business Logic to the App
Add business logic to the app and learn to call functions that belong to a package.
We'll cover the following...
So far, we have some code in our project in a package called coffee
. But how can we execute it? Like most languages, the execution point of entry in Go is the main
function (except when we use init
as the execution of entry).
Adding the main
function
Let's add a main.go
function.
Press + to interact
package mainimport ("fmt""coffeeshop/coffee")func main() {fmt.Println("Printing the list of coffees available in the CoffeeShop ")coffees, err := coffee.GetCoffees()for _, element := range coffees.List {result := fmt.Sprintf("%s for $%v", element.Name, element.Price)fmt.Println(result)}}
Quite a few things are going on in this file. Let's go over it line by line.
In line 1 ...