forked from ArchitectingSoftware/CNSE-Class-Demo-Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackages.go
More file actions
39 lines (31 loc) · 1.34 KB
/
Copy pathpackages.go
File metadata and controls
39 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"architectingsoftware.com/gotutorial/demopackage"
)
//This demo shows some unique aspects of packages in go. It uses
//the student.go file in the demopackage directory.
func basicPackageDemo() {
//This is a basic package demo. We are importing a package from the
//architectingsoftware.com/gotutorial/demopackage directory. This is a
//package that I created for this tutorial. It is not a standard go package.
//You can see the code for this package in the demopackage directory.
s := demopackage.New()
//Notice that we can easily access the exported fields (the ones that
//start with a capital letter) of the struct. We cannot access the
//unexported fields (the ones that start with a lowercase letter).
fmt.Println("NAME:", s.Name)
fmt.Println("YEAR:", s.Year)
fmt.Println("GPA:", s.GPA)
//We can also call the exported methods of the struct, but not the
//unexported methods. Thus we cannot see the SSN of the student,
//or the tuition balance. In order to operate on the unexported
//fields we need to use exported receiver methods.
fmt.Println("SSN:", s.GetSSN("secret"))
fmt.Println("Adjust Balance: ", "New Balance is:", s.AdjustBalance(100.0))
}
func RunPackagesDemo() {
fmt.Println("------ Running Packages Demo ------")
basicPackageDemo()
fmt.Printf("-----------------------------------\n\n")
}