1+ package greeting
2+
3+ import "fmt"
4+
5+ /**
6+ * User defined type Profile act as struct type
7+ */
8+ type Profile struct {
9+ Name string
10+ Username string
11+ Message string
12+ }
13+
14+ type Printer func (string ) ()
15+ /**
16+ * Define a CreateMessage function;
17+ *
18+ * username is variadic function, can only use ... as final argument in list
19+ */
20+ func CreateMessage (name , username , message string ) (welcome string , info string ) {
21+
22+ /**
23+ * <naming-return-val1> = string
24+ * <naming-return-val2> = string
25+ */
26+ welcome = "\n " + message + " " + name
27+ info = "You are authorize to access the system: " + username + "\n "
28+
29+ return
30+ }
31+
32+ func Print (s string ) {
33+ fmt .Print (s )
34+ }
35+
36+ func PrintLine (s string ) {
37+ fmt .Println (s )
38+ }
39+
40+ func CreatePrintFunction (custom string ) Printer {
41+ return func (s string ) {
42+ fmt .Println (s + custom )
43+ }
44+ }
45+
46+
47+ /**
48+ * Define a Greeting function;
49+ */
50+ func Greeting (github Profile , do Printer , isFormat bool ) {
51+
52+ wel , inf := CreateMessage (github .Name , github .Username , github .Message )
53+
54+ /**
55+ * Commenting exact below "Println(wel) line would throw an error "wel declared and not used"
56+ * In case you want to ignore the wel declaration and use info => replace wel with _ as below syntax
57+ *
58+ * E.g. _, info := CreateMessage(github.name, github.username, github.message)
59+ */
60+
61+ /**
62+ * if statement with embedded-statement
63+ * if [var] condition { ... } else { ... }
64+ */
65+ if prefix := "Mr: " ; isFormat {
66+ do (prefix + wel )
67+ } else {
68+ do (inf )
69+ }
70+
71+ // fmt.Println(_) // Cannot use _ as value
72+ }
0 commit comments