-
Notifications
You must be signed in to change notification settings - Fork 0
/
greet.go
94 lines (75 loc) · 2.15 KB
/
greet.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//This file consists of examples from the first week's class
package main
import (
"fmt"
"os"
)
func main() {
fmt.Println("Hello World")
greet("Berke") //calling greet function
//calling createGreet function
var name1 string = "Berke"
var greeting = createGreet(name1)
fmt.Printf("%s", greeting)
//calling createGreet2 function
name2 := os.Args[1]
greeting1 := createGreet2(name2)
fmt.Printf("%s\n", greeting1)
//taking input from user by using Scanln Funcion
var name3 string
fmt.Println("Please enter your name:")
fmt.Scanln(&name3)
greeting2 := createGreet2(name3)
fmt.Printf("%s\n", greeting2)
//Created an instance of Person.greet() method is called to greet the person
greeter := Person{"Mehmet"}
var greeting3 = greeter.greet()
fmt.Printf("%s\n", greeting3)
//Different greeting examples
greetPrinter(createGreetInTurkish, "Berk")
greetPrinter(createGreetInEnglish, "Mana")
greetCreator := createGreetInTurkish
greetPrinter(greetCreator, "Selen")
func(name string) {
greeting := "Selam " + name + " :)"
fmt.Printf("%s\n", greeting)
}("Kemal")
closure := func(name string) {
greeting := "Selam " + name + " :)"
fmt.Printf("%s\n", greeting)
}
closure("Emirhan")
anotherGreetPrinter(closure, "Batu")
}
//functions
func greet(name string) {
fmt.Printf("Selam %s :)\n", name)
}
func createGreet(name1 string) string {
greeting := "Selamlar " + name1 + " :) \n"
return greeting
}
func createGreet2(name2 string) string {
return "Merhaba " + name2 + " :)"
}
type Person struct {
name4 string
}
//Function greet() is associated with struct Person and so it becomes a method.
func (p Person) greet() string {
return "Selam " + p.name4 + " :)"
}
//Different greeting functions
func createGreetInTurkish(name string) string {
return "Selam " + name + " :)"
}
func createGreetInEnglish(name string) string {
return "Hi " + name + " :)"
}
func greetPrinter(function func(it string) string, name string){
var greeting = function(name)
fmt.Printf("%s\n", greeting)
}
func anotherGreetPrinter(function func(it string), name string){
function(name)
}