Adding Business Logic to the App
Explore how to implement business logic in a Go app by organizing code into packages and modules. Learn to add functions that manage and search data, run the app using the main function, and understand how to transition from running simple scripts to developing a service-oriented application.
We'll cover the following...
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.
Quite a few things are going on in this file. Let's go over it line by line.
In line 1, we declare a package
mainfor the file.In line 3, we start an import block. The first one is
fmt, ...