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+ * Either specify string for each or just make string at last parameter and first 2 will be asssumed as string
17+ * Also specify the return type which in case here is string
18+ *
19+ * func <function-name>([param1, param2, ...]) (<naming-return-val1><return-type1>, <naming-return-val1><return-type2>) { ... }
20+ */
21+ func CreateMessage (name , username , message string ) (welcome string , info string ) {
22+
23+ /**
24+ * <naming-return-val1> = string
25+ * <naming-return-val2> = string
26+ */
27+ welcome = "\n " + message + " " + name
28+ info = "You are authorize to access the system: " + username + "\n "
29+
30+ return
31+ }
32+
33+ /**
34+ * Define a Greeting function;
35+ */
36+ func Greeting (github Profile ) {
37+
38+ wel , inf := CreateMessage (github .name , github .username , github .message )
39+
40+ /**
41+ * Commenting exact below "Println(wel) line would throw an error "wel declared and not used"
42+ * In case you want to ignore the wel declaration and use info => replace wel with _ as below syntax
43+ *
44+ * E.g. _, info := CreateMessage(github.name, github.username, github.message)
45+ */
46+ fmt .Println (wel )
47+ fmt .Println (inf )
48+
49+ // fmt.Println(_) // Cannot use _ as value
50+ }
51+
52+ func main () {
53+
54+ var github = Profile {"Ashwin Hegde" , "hegdeashwin" , "Welcome to Go world!" }
55+
56+ /**
57+ * Call the function and pass the data to the function
58+ */
59+ Greeting (github )
60+ }
0 commit comments