Entities
Create new folder named entities. In entities folder, create new file named product.go as below:
package entities
type Product struct {
Id string
Name string
Price float64
Quantity int
Status bool
}
Application
Create new folder named src. In src folder, create new file named main.go as below:
package main
import (
"entities"
"fmt"
)
func main() {
product := Find()
fmt.Println("Product Info")
Display(product)
}
func Find() entities.Product {
product := entities.Product {
Id: "p02",
Name: "name 2",
Price: 5,
Quantity: 9,
Status: false,
}
return product
}
func Display(product entities.Product) {
fmt.Println("id: ", product.Id)
fmt.Println("name: ", product.Name)
fmt.Println("price: ", product.Price)
fmt.Println("quantity: ", product.Quantity)
fmt.Println("status: ", product.Status)
fmt.Println("total: ", (product.Price * float64(product.Quantity)))
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Product Info
id: p02
name: name 2
price: 5
quantity: 9
status: false
total: 45