Skip to content

Commit 9336295

Browse files
author
Ashwin Hegde
committed
Merge pull request #15 from hegdeashwin/develop
Develop
2 parents b658578 + 185b25f commit 9336295

File tree

9 files changed

+190
-0
lines changed

9 files changed

+190
-0
lines changed

codes/var-types-pointer-constants/helloworld.go renamed to codes/ch1_var-types-pointer-constants/helloworld.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func main() {
2121
/**
2222
* Declare a variable with string type and assign a string value to it;
2323
* Type is optional.
24+
*
25+
* Note: Declaring variable and do not use is an error in Go
2426
*/
2527
var message string
2628
message = "Welcome to Go World!"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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, ...]) <return-type> { ... }
20+
*/
21+
func CreateMessage(name, username, message string) string {
22+
return message + ", " + name + " (" + username + ")"
23+
}
24+
25+
/**
26+
* Define a Greeting function;
27+
*/
28+
func Greeting(github Profile) {
29+
fmt.Println(CreateMessage(github.name, github.username, github.message))
30+
}
31+
32+
func main() {
33+
34+
var github = Profile{"Ashwin Hegde", "hegdeashwin", "Welcome to Go world!"}
35+
36+
/**
37+
* Call the function and pass the data to the function
38+
*/
39+
Greeting(github)
40+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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, ...]) (<return-type1>, <return-type2>) { ... }
20+
*/
21+
func CreateMessage(name, username, message string) (string, string) {
22+
23+
/**
24+
* return <first-return>, <second-return>, ...
25+
*/
26+
return "\n" + message + " " + name, "You are authorize to access the system: " + username + "\n"
27+
}
28+
29+
/**
30+
* Define a Greeting function;
31+
*/
32+
func Greeting(github Profile) {
33+
34+
35+
welcome, info := CreateMessage(github.name, github.username, github.message)
36+
37+
/**
38+
* Commenting exact below "Println(welcome) line would throw an error "welcome declared and not used"
39+
* In case you want to ignore the welcome declaration and use info => replace welcome with _ as below syntax
40+
*
41+
* E.g. _, info := CreateMessage(github.name, github.username, github.message)
42+
*/
43+
fmt.Println(welcome)
44+
fmt.Println(info)
45+
46+
// fmt.Println(_) // Cannot use _ as value
47+
}
48+
49+
func main() {
50+
51+
var github = Profile{"Ashwin Hegde", "hegdeashwin", "Welcome to Go world!"}
52+
53+
/**
54+
* Call the function and pass the data to the function
55+
*/
56+
Greeting(github)
57+
}

codes/ch2_functions/function.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 Greeting function;
16+
*/
17+
func Greeting(github Profile) {
18+
fmt.Println("Name: ", github.name)
19+
fmt.Println("Username: ", github.username)
20+
fmt.Println("Message: ", github.message)
21+
}
22+
23+
func main() {
24+
25+
var github = Profile{"Ashwin Hegde", "hegdeashwin", "Welcome to Go world!"}
26+
27+
/**
28+
* Call the function and pass the data to the function
29+
*/
30+
Greeting(github)
31+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}

codes/functions/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)