1
+ package main
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
+ /**
15
+ * Define a CreateMessage function;
16
+ *
17
+ * username is variadic function, can only use ... as final argument in list
18
+ */
19
+ func CreateMessage (name string , username string , message ... string ) (welcome string , info string ) {
20
+
21
+ /**
22
+ * <naming-return-val1> = string
23
+ * <naming-return-val2> = string
24
+ */
25
+ welcome = "\n " + message [0 ] + " " + name
26
+ info = "You are authorize to access the system: " + username + "\n "
27
+
28
+ fmt .Println (message [1 ])
29
+ fmt .Println (message [2 ])
30
+ fmt .Println ("Number of parameters: " , len (message ))
31
+
32
+ return
33
+ }
34
+
35
+ /**
36
+ * Define a Greeting function;
37
+ */
38
+ func Greeting (github Profile ) {
39
+
40
+ wel , inf := CreateMessage (github .name , github .username , github .message , "Go is concurrent" , "Go is awesome" )
41
+
42
+ /**
43
+ * Commenting exact below "Println(wel) line would throw an error "wel declared and not used"
44
+ * In case you want to ignore the wel declaration and use info => replace wel with _ as below syntax
45
+ *
46
+ * E.g. _, info := CreateMessage(github.name, github.username, github.message)
47
+ */
48
+ fmt .Println (wel )
49
+ fmt .Println (inf )
50
+
51
+ // fmt.Println(_) // Cannot use _ as value
52
+ }
53
+
54
+ func main () {
55
+
56
+ var github = Profile {"Ashwin Hegde" , "hegdeashwin" , "Welcome to Go world!" }
57
+
58
+ /**
59
+ * Call the function and pass the data to the function
60
+ */
61
+ Greeting (github )
62
+ }
0 commit comments