├── 1. Beginners ├── 1. Variables │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 10. While Loop In Golang │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 11. Switch Statement │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 12. Arrays │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 13. Slices │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 14. Iterating Over Slice │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 15. Maps │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 16. Strucuts │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 17. Anonymous Structs │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 2. Constants │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 3. Booleans │ ├── README.md │ ├── challenges │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 4. Numbers │ ├── README.md │ ├── challenges │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 5. Strings │ ├── README.md │ ├── challenges │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 6. Comparison Operators │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 7. Logical Operators │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 8. Conditional Statement │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go └── 9. For Loop │ ├── README.md │ ├── challenge │ ├── instructions.txt │ └── main.go │ └── index.go ├── 2. Intermediate ├── 1. Functions │ ├── README.md │ ├── challenge │ │ ├── challenge.go │ │ └── instructions.txt │ └── index.go ├── 2. Function Expression │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 3. Anonymous Functions │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 4. Methods │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 5. Callback Functions │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 6. Defer Keyword │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go ├── 7. Scopes │ ├── README.md │ └── index.go ├── 8. Pointers │ ├── README.md │ ├── challenge │ │ ├── instructions.txt │ │ └── main.go │ └── index.go └── 9. Panic │ ├── README.md │ ├── challenge │ ├── instructions.txt │ └── main.go │ └── index.go ├── 3. Advance ├── 1. Interfaces │ ├── 1. example-one.go │ ├── 2. example-two.go │ ├── 3. example-three.go │ └── README.md ├── 2. Generics │ ├── README.md │ └── index.go ├── 3. Goroutines │ ├── README.md │ └── index.go ├── 4. Channels │ ├── 1. simple-example.go │ ├── 2. buffered and unbuffered.go │ └── README.md ├── 5. waitGroups │ ├── README.md │ └── index.go └── 6. Select │ ├── README.md │ └── index.go ├── README.md └── thumb.png /1. Beginners/1. Variables/README.md: -------------------------------------------------------------------------------- 1 | # Variables are containers for storing data values 2 | 3 | ## In Go, there are two ways to declare a variable 4 | 5 | ### 1. Use the var keyword, followed by variable name and type 6 | 7 | ```go 8 | package main 9 | import ("fmt") 10 | 11 | var name = "John Doe" // Variable One 12 | 13 | func main() { 14 | var fruit = "Apple" // Variable Two 15 | fmt.Println(name) 16 | fmt.Println(fruit) 17 | } 18 | ``` 19 | 20 | ### 2. Use the := sign, followed by the variable value 21 | 22 | ```go 23 | package main 24 | import ("fmt") 25 | 26 | func main() { 27 | varOne := 100 28 | varTwo := 2 29 | fmt.Println(varOne) 30 | fmt.Println(varTwo) 31 | } 32 | ``` 33 | 34 | ### Assigning Types + Type Inferred 35 | 36 | ```go 37 | package main 38 | import ("fmt") 39 | 40 | func main() { 41 | var fruit string = "Mango" // type is string 42 | var user = "HuXn" // type is inferred 43 | number := 2 // type is inferred 44 | 45 | fmt.Println(fruit) 46 | fmt.Println(user) 47 | fmt.Println(number) 48 | } 49 | ``` 50 | 51 | ### Go Multiple Variable Declaration 52 | 53 | ```go 54 | package main 55 | import ("fmt") 56 | 57 | func main() { 58 | var one, two, three, four, five int = 1, 2, 3, 4, 5 59 | 60 | fmt.Println(one) 61 | fmt.Println(two) 62 | fmt.Println(three) 63 | fmt.Println(four) 64 | } 65 | ``` 66 | 67 | ### Go Variable Declaration in a Block 68 | 69 | ```go 70 | package main 71 | import ("fmt") 72 | 73 | func main() { 74 | var ( 75 | num int 76 | number int = 1 77 | greetings string = "hello" 78 | ) 79 | 80 | fmt.Println(num) 81 | fmt.Println(number) 82 | fmt.Println(greetings) 83 | } 84 | ``` 85 | 86 | ## Go Variable Naming Rules 87 | 88 | #### 1. A variable name must start with a letter or an underscore character (\_) 89 | 90 | #### 2. A variable name cannot start with a digit 91 | 92 | #### 3. A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and \_ ) 93 | 94 | #### 4. Variable names are case-sensitive (age, Age and AGE are three different variables) 95 | 96 | #### 5. There is no limit on the length of the variable name 97 | 98 | #### 6. A variable name cannot contain spaces 99 | 100 | #### 7. The variable name cannot be any Go keywords 101 | -------------------------------------------------------------------------------- /1. Beginners/1. Variables/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create variable name (myFavNum) 2 | 2. Store your favorite number inside it 3 | 3. Print that variable to the console 4 | 4. Create new variable name (uniqueNumber) 5 | 5. Store the value of (10) inside it. 6 | 6. Print that to the console -------------------------------------------------------------------------------- /1. Beginners/1. Variables/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | myFavNum := 21 7 | fmt.Println(myFavNum) 8 | 9 | var uniqueNumber = 10 10 | fmt.Println(uniqueNumber) 11 | } 12 | -------------------------------------------------------------------------------- /1. Beginners/1. Variables/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // var number int = 20 6 | var number = 20 7 | 8 | func main() { 9 | fmt.Println(number) 10 | 11 | // Short Decoration Operator 12 | num := 1000 13 | fmt.Println(num) 14 | 15 | // Using Descreptive Names 16 | // UPPERCASE 👎 17 | // lowercase 👎 18 | // snack_case 👎 19 | // CamelCase 👍 20 | fullName := "HuXn WebDev" 21 | fmt.Println(fullName) 22 | 23 | // Unexpected Error In Variables 24 | 25 | // 1. 26 | // var name string = 20 // ERROR 27 | // fmt.Println(name) 28 | 29 | // 2. 30 | // var var = 20 31 | // fmt.Println(var) 32 | 33 | // 3. 34 | // var 1student = "alex" 35 | // fmt.Println(1student) 36 | 37 | // 4. 38 | // var Awesome animal = "dog" 39 | // fmt.Println(Awesome animal) 40 | 41 | // 5. 42 | // var special = 20 43 | // special = "Special String" 44 | // fmt.Println(special) 45 | } 46 | -------------------------------------------------------------------------------- /1. Beginners/10. While Loop In Golang/README.md: -------------------------------------------------------------------------------- 1 | # While Loop 2 | 3 | ## Unlike other programming languages, Go doesn't have a dedicated keyword for a while loop. However, we can use the for loop to perform the functionality of a while loop. 4 | 5 | ```go 6 | // Program to print numbers between 0 and 10 7 | package main 8 | import ("fmt") 9 | 10 | func main() { 11 | number := 0 12 | 13 | for number <= 10 { 14 | fmt.Println(number) 15 | number++ 16 | } 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /1. Beginners/10. While Loop In Golang/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Print numbers from 0 through 4 using while loop -------------------------------------------------------------------------------- /1. Beginners/10. While Loop In Golang/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | i := 0 7 | for i < 5 { 8 | fmt.Println(i) 9 | i++ 10 | } 11 | } -------------------------------------------------------------------------------- /1. Beginners/10. While Loop In Golang/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | x := 1 7 | 8 | for x <= 20 { 9 | fmt.Println(x) 10 | x++ 11 | } 12 | 13 | i := 0 14 | for i <= 5 { 15 | fmt.Println("Hello World", i) 16 | i++ 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /1. Beginners/11. Switch Statement/README.md: -------------------------------------------------------------------------------- 1 | # The switch Statement 2 | 3 | ## The switch statement allows us to execute one code block among many alternatives. 4 | 5 | ```go 6 | package main 7 | import ("fmt") 8 | 9 | func main() { 10 | day := 8 11 | 12 | switch day { 13 | case 1: 14 | fmt.Println("Monday") 15 | case 2: 16 | fmt.Println("Tuesday") 17 | case 3: 18 | fmt.Println("Wednesday") 19 | case 4: 20 | fmt.Println("Thursday") 21 | case 5: 22 | fmt.Println("Friday") 23 | case 6: 24 | fmt.Println("Saturday") 25 | case 7: 26 | fmt.Println("Sunday") 27 | default: 28 | fmt.Println("Not a weekday") 29 | } 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /1. Beginners/11. Switch Statement/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Perform this challenge using switch statment 2 | 3 | 1. Create variable (role) and store "guest" as a value 4 | 5 | 2. If the role is equal to "guest" print("Guest User") 6 | 7 | 3. If the role is equal to "moderator" print("Moderator User") 8 | 9 | 4. If role doesn't match print("Unknown User") -------------------------------------------------------------------------------- /1. Beginners/11. Switch Statement/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | role := "guest" 7 | switch { 8 | case (role == "guest"): 9 | fmt.Println("Guest User") 10 | case (role == "moderator"): 11 | fmt.Println("Moderator User") 12 | default: 13 | fmt.Println("Unknown User") 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /1. Beginners/11. Switch Statement/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | num := 1000 7 | 8 | switch { 9 | case (num > 5): 10 | fmt.Println("number is greater then 5") 11 | case (num < 5): 12 | fmt.Println("number is less then 5") 13 | case (num == 5): 14 | fmt.Println("number is equal to 5") 15 | } 16 | 17 | day := "friday" 18 | 19 | switch { 20 | case (day == "monday"): 21 | fmt.Println("Today is monday") 22 | case (day == "tuesday"): 23 | fmt.Println("Today is tuesday") 24 | case (day == "wednesday"): 25 | fmt.Println("Today is wednesday") 26 | case (day == "friday"): 27 | fmt.Println("Today is friday") 28 | case (day == "saturday"): 29 | fmt.Println("Today is saturday") 30 | case (day == "sunday"): 31 | fmt.Println("Today is sunday") 32 | default: 33 | fmt.Println("Don't know what day is today!") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /1. Beginners/12. Arrays/README.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | ### Arrays is a data structure which is use to store multiple values of the same type in a single variable, instead of declaring separate variables for each value. 4 | 5 | ### Arrays are 0 index based. 6 | 7 | ```go 8 | package main 9 | import ("fmt") 10 | 11 | func main() { 12 | var arr1 = [3]int{1,2,3} 13 | arr2 := [5]int{4,5,6,7,8} 14 | 15 | fmt.Println(arr1) 16 | fmt.Println(arr2) 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /1. Beginners/12. Arrays/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create array of 5 integers & log it to the console 2 | 2. Create friends array & store 3 friends inside it 3 | 3. Print arrays to the console -------------------------------------------------------------------------------- /1. Beginners/12. Arrays/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var numbers [5]int 7 | fmt.Println(numbers) 8 | 9 | var friends [3]string 10 | friends[0] = "HuXn" 11 | friends[1] = "John" 12 | friends[2] = "Jordan" 13 | fmt.Println(friends) 14 | } -------------------------------------------------------------------------------- /1. Beginners/12. Arrays/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // 1. Creating Array 7 | var numbers [5]int 8 | fmt.Println(numbers) 9 | 10 | // Adding Items to array 11 | numbers[0] = 10 12 | numbers[1] = 20 13 | numbers[2] = 30 14 | numbers[3] = 40 15 | numbers[4] = 50 16 | fmt.Println(numbers) 17 | 18 | // 3. Creating String array 19 | var peoples [3]string 20 | peoples[0] = "HuXn" // Adding items to string array 21 | peoples[1] = "John" // Adding items to string array 22 | peoples[2] = "Jordan" 23 | fmt.Println(peoples) 24 | 25 | // 4. Length & Capcity 26 | fmt.Println(len(peoples)) 27 | fmt.Println(cap(peoples)) 28 | 29 | // 5. Iterating over array. 30 | for item := 0; item < len(peoples); item++ { 31 | // fmt.Println(item) 32 | fmt.Println(peoples[item]) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /1. Beginners/13. Slices/README.md: -------------------------------------------------------------------------------- 1 | # Slices 2 | 3 | ### Slices are also used to store multiple values of the same type in a single variable, however unlike arrays, the length of a slice can grow and shrink as you see fit. 4 | 5 | ## There are several ways to create a slice 👇 6 | 7 | ### 1. Using the []datatype{values} format 8 | 9 | ### 2. Create a slice from an array 10 | 11 | ### 3. Using the make() function 12 | 13 | ```go 14 | // name := []datatype{values} 15 | // name := []int{} 16 | 17 | package main 18 | import ("fmt") 19 | 20 | func main() { 21 | myslice1 := []int{} 22 | fmt.Println(len(myslice1)) 23 | fmt.Println(cap(myslice1)) 24 | fmt.Println(myslice1) 25 | 26 | myslice2 := []string{"Go", "Slices", "Are", "Powerful"} 27 | fmt.Println(len(myslice2)) 28 | fmt.Println(cap(myslice2)) 29 | fmt.Println(myslice2) 30 | } 31 | ``` 32 | 33 | # Make() Method 34 | 35 | ### The make function will create a zeroed array and return a slice referencing an array. This is a great way to create a dynamically sized array. To create a slice using the make function, we need to specify three arguments: type, length and the capacity. 36 | 37 | ```go 38 | package main 39 | import "fmt" 40 | func main() { 41 | slice := make([]string, 3, 5) 42 | fmt.Println("Length", len(slice)) 43 | fmt.Println("Capacity", cap(slice)) 44 | fmt.Println(slice) 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /1. Beginners/13. Slices/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create numbers slice & store random numbers of your choice 2 | 3 | 2. Log all numbers which are stored in the slice 4 | 5 | 3. Log numbers from 0 through 5 index 6 | 7 | 4. Now append 5 more random numbers to that exsisting slice 8 | 9 | 5. Create slice using make built in function (type: int) 10 | (size: 5) 11 | (capacity: 20) 12 | 13 | 6. Print everything. -------------------------------------------------------------------------------- /1. Beginners/13. Slices/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | numbers := []int{42, 21, 11, 23, 44, 56, 20, 100, 200} 7 | // fmt.Println(numbers) 8 | fmt.Println(numbers[:]) 9 | fmt.Println(numbers[0:5]) 10 | numbers = append(numbers, 22, 12, 34, 11, 67, 90) 11 | fmt.Println(numbers) 12 | mySlice := make([]int, 5, 20) 13 | mySlice[2] = 20 14 | fmt.Println(mySlice) 15 | } -------------------------------------------------------------------------------- /1. Beginners/13. Slices/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | num := []int{10, 20, 30, 40, 50} 7 | fmt.Println(num) 8 | 9 | fmt.Println(num[:]) 10 | fmt.Println(num[1:]) 11 | fmt.Println(num[1:3]) 12 | 13 | num = append(num, 60, 70, 80, 90) 14 | fmt.Println(num) 15 | 16 | num2 := make([]int, 5, 20) 17 | fmt.Println(num2) 18 | 19 | num2[2] = 5 20 | fmt.Println(num2) 21 | // num2[6] = 30 22 | // fmt.Println(num2) 23 | } 24 | -------------------------------------------------------------------------------- /1. Beginners/14. Iterating Over Slice/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Iterate over this massive slice & print each member with index 2 | 3 | Result should look like this 👇 4 | 5 | 0 - Rémi Denis-Courmont 6 | 1 - Jean-Baptiste Kempf 7 | 2 - Laurent Aimar 8 | 3 - Gildas Bazin 9 | 4 - Felix Paul Kühne 10 | 5 - Rafaël Carré 11 | ... -------------------------------------------------------------------------------- /1. Beginners/14. Iterating Over Slice/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | vlcAuthors := []string { 7 | "Rémi Denis-Courmont", 8 | "Jean-Baptiste Kempf", 9 | "Laurent Aimar", 10 | "Gildas Bazin", 11 | "Felix Paul Kühne", 12 | "Rafaël Carré", 13 | "Pierre d'Herbemont", 14 | "Rémi Duraffort", 15 | "Derk-Jan Hartman", 16 | "Antoine Cellerier", 17 | "Samuel Hocevar", 18 | "Jean-Paul Saman", 19 | "Christophe Mutricy", 20 | "Clément Stenac", 21 | "Christophe Massiot", 22 | "Ilkka Ollakka", 23 | "Pierre Ynard", 24 | "François Cartegnie", 25 | "Damien Fouilleul", 26 | "Sigmund Augdal Helberg", 27 | "Erwan Tulou", 28 | "David Fuhrmann", 29 | "Olivier Teulière", 30 | "Cyril Deguet", 31 | "Eric Petit", 32 | "Filippo Carone", 33 | "Rocky Bernstein", 34 | "Hugo Beauzée-Luyssen", 35 | "Olivier Aubert", 36 | "Pavlov Konstantin", 37 | "Jakob Leben", 38 | "Benjamin Pracht", 39 | "Jean-Philippe André", 40 | "Steve Lhomme", 41 | "Stéphane Borel", 42 | "JP Dinger", 43 | "Geoffroy Couprie", 44 | "Martin Storsjö", 45 | "Marian Ďurkovič", 46 | "Ludovic Fauvet", 47 | "Yoann Peronneau", 48 | "Sébastien Escudier", 49 | "Jon Lech Johansen", 50 | "KO Myung-Hun", 51 | "Edward Wang", 52 | "Dennis van Amerongen", 53 | "Faustino Osuna", 54 | "Mirsal Ennaime", 55 | "Denis Charmet", 56 | "Jérôme Decoodt", 57 | "Loïc Minier", 58 | "David Flynn", 59 | "Frédéric Yhuel", 60 | "Kaarlo Raiha", 61 | "Mark Moriarty", 62 | "Christopher Mueller", 63 | "Fabio Ritrovato", 64 | "Tony Castley", 65 | "Srikanth Raju", 66 | "Michel Kaempf", 67 | "Jean-Marc Dressler", 68 | "Johan Bilien", 69 | "Vincent Seguin", 70 | "Simon Latapie", 71 | "Bernie Purcell", 72 | "Henri Fallon", 73 | "Sebastien Zwickert", 74 | "Christoph Miebach", 75 | "Adrien Maglo", 76 | "Emmanuel Puig", 77 | "Renaud Dartus", 78 | "Alexis de Lattre", 79 | "Vincent Penquerch", 80 | "Arnaud de Bossoreille de Ribou", 81 | "Mohammed Adnène Trojette", 82 | "Boris Dorès", 83 | "Jai Menon", 84 | "Anil Daoud", 85 | "Daniel Mierswa", 86 | "Naohiro Koriyama", 87 | "Rob Jonson", 88 | "Pierre Baillet", 89 | "Dominique Leuenberger", 90 | "Andre Pang", 91 | "Zoran Turalija", 92 | "Akash Mehrotra", 93 | "André Weber", 94 | "Anthony Loiseau", 95 | "Lukas Durfina", 96 | "Xavier Marchesini", 97 | "Cyril Mathé", 98 | "Devin Heitmueller", 99 | "Juho Vähä-Herttua", 100 | "Ken Self", 101 | "Alexis Ballier", 102 | "Juha Jeronen", 103 | "Nicolas Chauvet", 104 | "Richard Hosking", 105 | "Éric Lassauge", 106 | "Marc Ariberti", 107 | "Sébastien Toque", 108 | "Tobias Güntner", 109 | "Benoit Steiner", 110 | "Michel Lespinasse", 111 | "Carlo Calabrò", 112 | "Cheng Sun", 113 | "Michał Trzebiatowski", 114 | "Brad Smith", 115 | "Brendon Justin", 116 | "Alexey Sokolov", 117 | "Basos G", 118 | "Philippe Morin", 119 | "Steinar H. Gunderson", 120 | "Vicente Jimenez Aguilar", 121 | "Yuval Tze", 122 | "Yves Duret", 123 | "Benjamin Drung", 124 | "Michael Hanselmann", 125 | "Alex Merry", 126 | "Damien Lucas", 127 | "Grigori Goronzy", 128 | "Richard Shepherd", 129 | "Gaël Hendryckx", 130 | "Michael Feurstein", 131 | "Stephan Assmus", 132 | "Adrien Grand", 133 | "Colin Guthrie", 134 | "David Menestrina", 135 | "Dominique Martinet", 136 | "Gleb Pinigin", 137 | "Jason Luka", 138 | "Luc Saillard", 139 | "Luca Barbato", 140 | "Mario Speiß", 141 | "Pankaj Yadav", 142 | "Ramiro Polla", 143 | "Ronald Wright", 144 | "Rui Zhang", 145 | "Can Wu", 146 | "Christophe Courtaut", 147 | "FUJISAWA Tooru", 148 | "Hannes Domani", 149 | "Manol Manolov", 150 | "Timothy B. Terriberry", 151 | "Antoine Lejeune", 152 | "Arnaud Schauly", 153 | "Branko Kokanovic", 154 | "Dylan Yudaken", 155 | "Florian G. Pflug", 156 | "François Revol", 157 | "G Finch", 158 | "Keary Griffin", 159 | "Konstanty Bialkowski", 160 | "Ming Hu", 161 | "Philippe Coent", 162 | "Przemyslaw Fiala", 163 | "Tanguy Krotoff", 164 | "Vianney BOYER", 165 | "Casian Andrei", 166 | "Chris Smowton", 167 | "David Kaplan", 168 | "Eugenio Jarosiewicz", 169 | "Fabian Keil", 170 | "Guillaume Poussel", 171 | "John Peterson", 172 | "Justus Piater", 173 | "Mark Lee", 174 | "Martin T. H. Sandsmark", 175 | "Rune Botten", 176 | "Søren Bøg", 177 | "Toralf Niebuhr", 178 | "Tristan Matthews", 179 | "Angelo Haller", 180 | "Aurélien Nephtali", 181 | "Austin Burrow", 182 | "Bill C. Riemers", 183 | "Colin Delacroix", 184 | "Cristian Maglie", 185 | "Elminster2031", 186 | "Jakub Wieczorek", 187 | "John Freed", 188 | "Mark Hassman", 189 | "Martin Briza", 190 | "Mike Houben", 191 | "Romain Goyet", 192 | "Adrian Yanes", 193 | "Alexander Lakhin", 194 | "Anatoliy Anischovich", 195 | "Barry Wardell", 196 | "Ben Hutchings", 197 | "Besnard Jean-Baptiste", 198 | "Brian Weaver", 199 | "Clement Chesnin", 200 | "David Geldreich", 201 | "Diego Elio Pettenò", 202 | "Diego Fernando Nieto", 203 | "Georgi Chorbadzhiyski", 204 | "Jon Stacey", 205 | "Jonathan Rosser", 206 | "Joris van Rooij", 207 | "Kaloyan Kovachev", 208 | "Katsushi Kobayashi", 209 | "Kelly Anderson", 210 | "Loren Merritt", 211 | "Maciej Blizinski", 212 | "Mark Bidewell", 213 | "Miguel Angel Cabrera Moya", 214 | "Niles Bindel", 215 | "Samuel Pitoiset", 216 | "Scott Caudle", 217 | "Sean Robinson", 218 | "Sergey Radionov", 219 | "Simon Hailes", 220 | "Stephen Parry", 221 | "Sukrit Sangwan", 222 | "Thierry Reding", 223 | "Xavier Martin", 224 | "Alex Converse", 225 | "Alexander Bethke", 226 | "Alexandre Ratchov", 227 | "Andres Krapf", 228 | "Andrey Utkin", 229 | "Andri Pálsson", 230 | "Andy Chenee", 231 | "Anuradha Suraparaju", 232 | "Benjamin Poulain", 233 | "Brieuc Jeunhomme", 234 | "Chris Clayton", 235 | "Clément Lecigne", 236 | "Cédric Cocquebert", 237 | "Daniel Peng", 238 | "Danny Wood", 239 | "David K", 240 | "Edouard Gomez", 241 | "Emmanuel de Roux", 242 | "Frode Tennebø", 243 | "GBX", 244 | "Gaurav Narula", 245 | "Geraud CONTINSOUZAS", 246 | "Hugues Fruchet", 247 | "Jan Winter", 248 | "Jean-François Massol", 249 | "Jean-Philippe Grimaldi", 250 | "Josh Watzman", 251 | "Kai Lauterbach", 252 | "Konstantin Bogdanov", 253 | "Kuan-Chung Chiu", 254 | "Kuang Rufan", 255 | "Matthias Dahl", 256 | "Michael McEll", 257 | "Michael Ploujnikov", 258 | "Mike Schrag", 259 | "Nickolai Zeldovich", 260 | "Nicolas Bertrand", 261 | "Niklas Hayer", 262 | "Olafs Vandāns", 263 | "Olivier Gambier", 264 | "Paul Corke", 265 | "Ron Frederick", 266 | "Rov Juvano", 267 | "Sabourin Gilles", 268 | "Sam Lade", 269 | "Sandeep Kumar", 270 | "Sasha Koruga", 271 | "Sreng Jean", 272 | "Sven Petai", 273 | "Tomas Krotil", 274 | "Tomer Barletz", 275 | "Tristan Leteurtre", 276 | "Vittorio Giovara", 277 | "Wang Bo", 278 | "maxime Ripard", 279 | "xxcv", 280 | "Adam Hoka", 281 | "Adrian Knoth", 282 | "Adrien Cunin", 283 | "Alan Fischer", 284 | "Alan McCosh", 285 | "Alex Helfet", 286 | "Alexander Terentyev", 287 | "Alexandre Ferreira", 288 | "Alina Friedrichsen", 289 | "An L. Ber", 290 | "Andreas Schlick", 291 | "Andrew Schubert", 292 | "Andrey Makhnutin", 293 | "Arnaud Vallat", 294 | "Asad Mehmood", 295 | "Ashok Bhat", 296 | "Austin English", 297 | "Baptiste Coudurier", 298 | "Benoit Calvez", 299 | "Björn Stenberg", 300 | "Blake Livingston", 301 | "Brandon Brooks", 302 | "Brian Johnson", 303 | "Brian Kurle", 304 | "Cezar Elnazli", 305 | "Chris White", 306 | "Christian Masus", 307 | "Christoph Pfister", 308 | "Christoph Seibert", 309 | "Christopher Key", 310 | "Christopher Rath", 311 | "Claudio Ortelli", 312 | "Cody Russell", 313 | "Cristian Morales Vega", 314 | "Dan Rosenberg", 315 | "Daniel Marth", 316 | "Daniel Tisza", 317 | "Detlef Schroeder", 318 | "Diego Biurrun", 319 | "Dominik Rathann Mierzejewski", 320 | "Duncan Salerno", 321 | "Edward Sheldrake", 322 | "Elliot Murphy", 323 | "Eren Inan Canpolat", 324 | "Ernest E. Teem III", 325 | "Etienne Membrives", 326 | "Fargier Sylvain", 327 | "Fathi Boudra", 328 | "Felix Geyer", 329 | "Filipe Azevedo", 330 | "Finn Hughes", 331 | "Florian Hubold", 332 | "Florian Roeske", 333 | "Frank Enderle", 334 | "Frédéric Crozat", 335 | "Georg Seifert", 336 | "Gertjan Van Droogenbroeck", 337 | "Gilles Chanteperdrix", 338 | "Greg Farrell", 339 | "Gregory Maxwell", 340 | "Gwenole Beauchesne", 341 | "Götz Waschk", 342 | "Hans-Kristian Arntzen", 343 | "Harry Sintonen", 344 | "Iain Wade", 345 | "Ibraheem Paredath", 346 | "Isamu Arimoto", 347 | "Ismael Luceno", 348 | "James Bates", 349 | "James Bond", 350 | "James Turner", 351 | "Janne Grunau", 352 | "Janne Kujanpää", 353 | "Jarmo Torvinen", 354 | "Jason Scheunemann", 355 | "Jeff Lu", 356 | "Jeroen Ost", 357 | "Joe Taber", 358 | "Johann Ransay", 359 | "Johannes Weißl", 360 | "John Hendrikx", 361 | "John Stebbins", 362 | "Jonas Gehring", 363 | "Joseph S. Atkinson", 364 | "Juergen Lock", 365 | "Julien Lta BALLET", 366 | "Julien / Gellule", 367 | "Julien Humbert", 368 | "Kamil Baldyga", 369 | "Kamil Klimek", 370 | "Karlheinz Wohlmuth", 371 | "Kevin Anthony", 372 | "Kevin DuBois", 373 | "Lari Natri", 374 | "Lorenzo Pistone", 375 | "Lucas C. Villa Real", 376 | "Lukáš Lalinský", 377 | "Mal Graty", 378 | "Malte Tancred", 379 | "Martin Pöhlmann", 380 | "Martin Zeman", 381 | "Marton Balint", 382 | "Mathew King", 383 | "Mathieu Sonet", 384 | "Matthew A. Townsend", 385 | "Matthias Bauer", 386 | "Mika Tiainen", 387 | "Mike Cardillo", 388 | "Mounir Lamouri (volkmar)", 389 | "Natanael Copa", 390 | "Nathan Phillip Brink", 391 | "Nick Briggs", 392 | "Nick Pope", 393 | "Nil Geiswiller", 394 | "Pascal Thomet", 395 | "Pere Orga", 396 | "Peter Bak Nielsen", 397 | "Phil Roffe and David Grellscheid", 398 | "Philip Sequeira", 399 | "Pierre Souchay", 400 | "Piotr Fusik", 401 | "Pádraig Brady", 402 | "R.M", 403 | "Ralph Giles", 404 | "Ramon Gabarró", 405 | "Robert Forsman", 406 | "Robert Jedrzejczyk", 407 | "Robert Paciorek", 408 | "Rolf Ahrenberg", 409 | "Roman Pen", 410 | "Ruud Althuizen", 411 | "Samuli Suominen", 412 | "Scott Lyons", 413 | "Sebastian Birk", 414 | "Sergey Puzanov", 415 | "Sergio Ammirata", 416 | "Sharad Dixit", 417 | "Song Ye Wen", 418 | "Stephan Krempel", 419 | "Steven Kramer", 420 | "Steven Sheehy", 421 | "Sveinung Kvilhaugsvik", 422 | "Sylvain Cadhillac", 423 | "Sylver Bruneau", 424 | "Takahito HIRANO", 425 | "Theron Lewis", 426 | "Thijs Alkemade", 427 | "Tillmann Karras", 428 | "Timo Paulssen", 429 | "Timo Rothenpieler", 430 | "Tobias Rapp", 431 | "Tomasen", 432 | "Tony Vankrunkelsven", 433 | "Tristan Heaven", 434 | "Varphone Wong", 435 | "Vasily Fomin", 436 | "Vikram Narayanan", 437 | "Yannick Bréhon", 438 | "Yavor Doganov", 439 | "Yohann Martineau", 440 | "dharani.prabhu.s", 441 | "suheaven", 442 | "wucan", 443 | "김정은", 444 | "Adam Sampson", 445 | "Alexander Gall", 446 | "Alex Antropoff", 447 | "Alexis Guillard", 448 | "Alex Izvorski", 449 | "Amir Gouini", 450 | "Andrea Guzzo", 451 | "Andrew Flintham", 452 | "Andrew Zaikin", 453 | "Andy Lindsay", 454 | "Arai/Fujisawa Tooru", 455 | "Arkadiusz Miskiewicz", 456 | "Arnaud Gomes-do-Vale", 457 | "Arwed v. Merkatz", 458 | "Barak Ori", 459 | "Basil Achermann", 460 | "Benjamin Mironer", 461 | "Bill", 462 | "Bob Maguire", 463 | "Brian C. Wiles", 464 | "Brian Raymond", 465 | "Brian Robb", 466 | "Carsten Gottbehüt", 467 | "Carsten Haitzler", 468 | "Charles Hordis", 469 | "Chris Clepper", 470 | "Christian Henz", 471 | "Christof Baumgaertner", 472 | "Christophe Burgalat", 473 | "Christopher Johnson", 474 | "Cian Duffy", 475 | "Colin Simmonds", 476 | "Damian Ivereigh", 477 | "Daniel Fischer", 478 | "Daniel Stränger", 479 | "Danko Dolch", 480 | "Dennis Lou", 481 | "Dermot McGahon", 482 | "Douglas West", 483 | "Dugal Harris", 484 | "Emmanuel Blindauer", 485 | "Enrico Gueli", 486 | "Enrique Osuna", 487 | "Eren Türkay", 488 | "Eric Dudiak", 489 | "Espen Skoglund", 490 | "Ethan C. Baldridge", 491 | "François Seingier", 492 | "Frans van Veen", 493 | "Frédéric Ruget", 494 | "Gerald Hansink", 495 | "Gisle Vanem", 496 | "Glen Gray", 497 | "Goetz Waschk", 498 | "Gregory Hazel", 499 | "Gustaf Neumann", 500 | "Hang Su", 501 | "Hans Lambermont", 502 | "Hans-Peter Jansen", 503 | "Harris Dugal", 504 | "Heiko Panther", 505 | "Igor Helman", 506 | "Isaac Osunkunle", 507 | "Jan David Mol", 508 | "Jan Gerber", 509 | "Jan Van Boghout", 510 | "Jasper Alias", 511 | "Jean-Alexis Montignies", 512 | "Jean-Baptiste Le Stang", 513 | "Jeffrey Baker", 514 | "Jeroen Massar", 515 | "Jérôme Guilbaud", 516 | "Johannes Buchner", 517 | "Johen Michael Zorko", 518 | "Johnathan Rosser", 519 | "John Dalgliesh", 520 | "John Paul Lorenti", 521 | "Jörg", 522 | "Joseph Tulou", 523 | "Julien Blache", 524 | "Julien Plissonneau Duquène", 525 | "Julien Robert", 526 | "Kenneth Ostby", 527 | "Kenneth Self", 528 | "Kevin H. Patterson", 529 | "Koehler, Vitally", 530 | "K. Staring", 531 | "Lahiru Lakmal Priyadarshana", 532 | "Laurent Mutricy", 533 | "Leo Spalteholz", 534 | "Loox Thefuture", 535 | "Marc Nolette", 536 | "Marco Munderloh", 537 | "Mark Gritter", 538 | "Markus Kern", 539 | "Markus Kuespert", 540 | "Martin Hamrle", 541 | "Martin Kahr", 542 | "Mateus Krepsky Ludwich", 543 | "Mathias Kretschmer", 544 | "Mats Rojestal", 545 | "Matthias P. Nowak", 546 | "Matthieu Lochegnies", 547 | "Michael Mondragon", 548 | "Michael S. Feurstein", 549 | "Michel Lanners", 550 | "Mickael Hoerdt", 551 | "Miguel Angel Cabrera", 552 | "Mikko Hirvonen", 553 | "Moritz Bunkus", 554 | "Nilmoni Deb", 555 | "Olivier Houchard", 556 | "Olivier Pomel", 557 | "Ondrej Kuda aka Albert", 558 | "Øyvind Kolbu", 559 | "Pascal Levesque", 560 | "Patrick Horn", 561 | "Patrick McLean", 562 | "Pauline Castets", 563 | "Paul Mackerras", 564 | "Peter Surda", 565 | "Petr Vacek", 566 | "Philippe Van Hecke", 567 | "Pierre-Luc Beaudoin", 568 | "Pierre Marc Dumuid", 569 | "Régis Duchesne", 570 | "Remco Poortinga", 571 | "Rene Gollent", 572 | "Rob Casey", 573 | "Robson Braga Araujo", 574 | "Roine Gustafsson", 575 | "Roman Bednarek", 576 | "Rudolf Cornelissen", 577 | "Sašo Kiselkov", 578 | "Sebastian Jenny", 579 | "Shane Harper", 580 | "Stefán Freyr Stefánsson", 581 | "Steve Brown", 582 | "Steven M. Schultz", 583 | "Tapio Hiltunen", 584 | "Thomas L. Wood", 585 | "Thomas Mühlgrabner", 586 | "Thomas Parmelan", 587 | "Tim O Callagha", 588 | "Tim Schuerewegen", 589 | "Tong Ka Man", 590 | "Torsten Spindler", 591 | "Udo Richter", 592 | "Vincent Dimar", 593 | "Vincent Penne", 594 | "Vitalijus Slavinskas", 595 | "Vitaly V. Bursov", 596 | "Vladimir Chernyshov", 597 | "Wade Majors", 598 | "Wallace Wadge", 599 | "Watanabe Go", 600 | "William Hawkins", 601 | "Xavier Maillard", 602 | "Ye zhang", 603 | "Yuehua Zhao", 604 | } 605 | for index, value := range vlcAuthors { 606 | fmt.Println(index, "-", value) 607 | } 608 | } -------------------------------------------------------------------------------- /1. Beginners/14. Iterating Over Slice/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | ppls := []string{"HuXn", "John", "Jordan"} 7 | 8 | for i := 0; i < len(ppls); i++ { 9 | fmt.Println(ppls[i]) 10 | } 11 | 12 | for index, value := range ppls { 13 | fmt.Println(index, value) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /1. Beginners/15. Maps/README.md: -------------------------------------------------------------------------------- 1 | # Maps 2 | 3 | ### Maps are a data structure which allow us to store data values in key:value pairs. 4 | 5 | ### A map is an unordered and changeable collection that does not allow duplicates. 6 | 7 | ### The default value of a map is nil. 8 | 9 | ```go 10 | userInfo := map[string]int{ 11 | "huxn": 17, 12 | "alex": 18, 13 | "john": 27, 14 | } 15 | 16 | fmt.Println(userInfo) 17 | userInfo["jordan"] = 15 18 | fmt.Println(userInfo["huxn"]) 19 | fmt.Println(userInfo["alex"]) 20 | fmt.Println(userInfo["john"]) 21 | ``` 22 | -------------------------------------------------------------------------------- /1. Beginners/15. Maps/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a userInfo map with three users & give each user different profession for example: 2 | 3 | "huxn": "Full-Stack Developer", 4 | "john": "Front-End Developer", 5 | "jordan": "Back-End Developer", 6 | 7 | 2. Add new user (Kumar) with different profession 8 | 9 | 3. Print userInfo 10 | 11 | 4. Now delete "huxn" from userInfo 12 | 13 | 5. Create randNums map and store the following data 14 | 15 | 0: 10, 16 | 1: 20, 17 | 2: 30, 18 | 3: 40, 19 | 4: 50, 20 | 21 | 6. Now log it to the console -------------------------------------------------------------------------------- /1. Beginners/15. Maps/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | usersInfo := map[string]string { 7 | "huxn": "Full-Stack Developer", 8 | "john": "Front-End Developer", 9 | "jordan": "Back-End Developer", 10 | } 11 | 12 | usersInfo["Kumar"] = "UX/UI Developer" 13 | fmt.Println(usersInfo) 14 | 15 | delete(usersInfo, "huxn") 16 | fmt.Println(usersInfo) 17 | 18 | randNums := map[int]int { 19 | 0: 10, 20 | 1: 20, 21 | 2: 30, 22 | 3: 40, 23 | 4: 50, 24 | } 25 | 26 | fmt.Println(randNums) 27 | } -------------------------------------------------------------------------------- /1. Beginners/15. Maps/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // ------------------------------------------- 7 | // 1. Creating Map 8 | userData := map[string]int{ 9 | "huxn": 17, 10 | "alex": 18, 11 | "john": 27, 12 | } 13 | 14 | // 2. Printing Map 15 | fmt.Println(userData) 16 | 17 | // 3. Assigning new values to Map 18 | userData["jordan"] = 15 19 | 20 | // 4. Accessing values from Map 21 | fmt.Println(userData["huxn"]) 22 | fmt.Println(userData["alex"]) 23 | fmt.Println(userData["john"]) 24 | 25 | // 5. Iterating Over Map 26 | for prop, value := range userData { 27 | fmt.Println(prop, value) 28 | } 29 | fmt.Println(userData) 30 | 31 | // 6. Deleting Items from Map 32 | delete(userData, "john") 33 | fmt.Println(userData) 34 | // ------------------------------------------- 35 | 36 | // ------------------------------------------- 37 | studentsMarks := map[string]int{ 38 | "huxn": 30, 39 | "john": 50, 40 | "alex": 70, 41 | "Abdul": 100, 42 | } 43 | 44 | fmt.Println(studentsMarks) 45 | fmt.Print(studentsMarks["Abdul"]) 46 | delete(studentsMarks, "Abdul") 47 | fmt.Println("------------------------") 48 | fmt.Println(studentsMarks) 49 | // ------------------------------------------- 50 | 51 | // ------------------------------------------- 52 | newStudentsData := map[int]string{ 53 | 1: "alex", 54 | 2: "John", 55 | 3: "Jordan", 56 | 4: "HuXn", 57 | 5: "Abdul", 58 | } 59 | 60 | fmt.Println(newStudentsData[4]) 61 | // ------------------------------------------- 62 | } 63 | -------------------------------------------------------------------------------- /1. Beginners/16. Strucuts/README.md: -------------------------------------------------------------------------------- 1 | # Structs (Structures) 2 | 3 | ### A struct is used to create a collection of members of different data types, into a single variable. 4 | 5 | ```go 6 | package main 7 | import ("fmt") 8 | 9 | type Person struct { 10 | name string 11 | age int 12 | job string 13 | salary int 14 | } 15 | 16 | func main() { 17 | var userOne Person 18 | 19 | userOne.name = "HuXn" 20 | userOne.age = 18 21 | userOne.job = "Programmer" 22 | userOne.salary = 40000 23 | fmt.Println(userOne) 24 | fmt.Println("My name is", userOne.name, "I'm", userOne.age, "Years old", "My Profession is", userOne.job, "My salary is", userOne.salary) 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /1. Beginners/16. Strucuts/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a movie struct with the following properties 2 | [title String] 3 | [mType string] 4 | [rating int] 5 | comments 6 | 7 | 2. Create comments struct with the following properties 8 | [author string] 9 | [body string] 10 | 11 | 3. Create instance of these structs and provide your favorite values 12 | 13 | 4. Finnaly print the result as follows 14 | 15 | fmt.Println("My Favorite Movie " + "(" + MOVIE TITLE HERE + ")" + " has", MOVIE RATING, "Ratings") 16 | 17 | fmt.Println(m.comments.author + " say's : " + m.comments.body) -------------------------------------------------------------------------------- /1. Beginners/16. Strucuts/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type movie struct { 6 | title string 7 | mType string 8 | rating int 9 | comments 10 | } 11 | 12 | type comments struct { 13 | author string 14 | body string 15 | } 16 | 17 | func main() { 18 | m := movie { 19 | title: "The Social Network", 20 | mType: "Programming", 21 | rating: 20, 22 | comments: comments { 23 | author: "HuXn", 24 | body: "Awesome Movie", 25 | }, 26 | } 27 | 28 | // fmt.Println(m) 29 | fmt.Println("My Favorite Movie " + "(" + m.title + ")" + " has", m.rating, "Ratings") 30 | fmt.Println(m.comments.author + " say's : " + m.comments.body) 31 | } -------------------------------------------------------------------------------- /1. Beginners/16. Strucuts/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type person struct { 6 | firstName string 7 | lastName string 8 | } 9 | 10 | type programmer struct { 11 | person 12 | isProgrammer bool 13 | } 14 | 15 | func main() { 16 | h := programmer{ 17 | person: person{ 18 | firstName: "HuXn", 19 | lastName: "WebDev", 20 | }, 21 | isProgrammer: true, 22 | } 23 | 24 | fmt.Println(h.firstName, h.lastName, h.isProgrammer) 25 | } 26 | -------------------------------------------------------------------------------- /1. Beginners/17. Anonymous Structs/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Take your previous challenge code and make structs annonymous, finally test your code -------------------------------------------------------------------------------- /1. Beginners/17. Anonymous Structs/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | type comments struct { 7 | author string 8 | body string 9 | } 10 | 11 | m := struct { 12 | title string 13 | mType string 14 | rating int 15 | comments 16 | } { 17 | title: "The Social Network", 18 | mType: "Programming", 19 | rating: 20, 20 | comments: comments { 21 | author: "HuXn", 22 | body: "Awesome Movie", 23 | }, 24 | } 25 | 26 | fmt.Println("My Favorite Movie " + "(" + m.title + ")" + " has", m.rating, "Ratings") 27 | fmt.Println(m.comments.author + " say's : " + m.comments.body) 28 | } -------------------------------------------------------------------------------- /1. Beginners/17. Anonymous Structs/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | h := struct { 7 | firstName string 8 | lastName string 9 | }{ 10 | firstName: "HuXn", 11 | lastName: "WebDev", 12 | } 13 | 14 | fmt.Println(h.firstName, h.lastName) 15 | } 16 | -------------------------------------------------------------------------------- /1. Beginners/2. Constants/README.md: -------------------------------------------------------------------------------- 1 | # The const keyword declares the variable as "constant", which means that it is unchangeable and read-only. 2 | 3 | ```go 4 | 5 | package main 6 | import ("fmt") 7 | 8 | const user = "admin" // cannot be changed 9 | 10 | func main() { 11 | fmt.Println("admin") 12 | } 13 | 14 | ``` 15 | 16 | # Constant Rules 17 | 18 | ### 1. Constant names follow the same naming rules as variables 19 | 20 | ### 2. Constant names are usually written in uppercase letters 21 | 22 | ### 3. Constants can be declared both inside and outside of a function 23 | -------------------------------------------------------------------------------- /1. Beginners/2. Constants/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Creat constant name (myConst) 2 | 2. Store 20 as a value 3 | 3. Create (x, y, z) in one go 4 | 4. Log all constants to the console -------------------------------------------------------------------------------- /1. Beginners/2. Constants/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const myConst = 32 6 | 7 | const ( 8 | x = 10 9 | y = 20 10 | z = 30 11 | ) 12 | 13 | func main() { 14 | fmt.Println(myConst) 15 | fmt.Println(x) 16 | fmt.Println(y) 17 | fmt.Println(z) 18 | } 19 | -------------------------------------------------------------------------------- /1. Beginners/2. Constants/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const ( 6 | a = 10 7 | b = 20 8 | c = 30 9 | d = 40 10 | ) 11 | 12 | func main() { 13 | fmt.Println(a) 14 | fmt.Println(b) 15 | fmt.Println(c) 16 | fmt.Println(d) 17 | 18 | var fruit string = "Apple" 19 | fruit = "Mango" // it will work 20 | fmt.Println(fruit) 21 | 22 | // You can also write it without specifying type. 23 | // const apple = "Apple" 24 | // apple = "Mango" // Error 25 | // fmt.Println(apple) 26 | 27 | const ( 28 | one = "John" 29 | two = "Alex" 30 | three = "HuXn" 31 | ) 32 | 33 | // ERROR 34 | // one = "Alex" 35 | // two = "John" 36 | // three = "Nina" 37 | 38 | fmt.Println(one) 39 | fmt.Println(two) 40 | fmt.Println(three) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /1. Beginners/3. Booleans/README.md: -------------------------------------------------------------------------------- 1 | # A boolean data-type can either be "TRUE" or "FALSE" 2 | 3 | ```go 4 | 5 | package main 6 | 7 | import "fmt" 8 | 9 | func main() { 10 | isGolangPL := true 11 | isHtmlPL := false 12 | fmt.Println(isGolangPL) 13 | fmt.Println(isHtmlPL) 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /1. Beginners/3. Booleans/challenges/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create variable name (huxnProgrammer) 2 | 2. Store true as a value 3 | 3. Create variable name (huxnLoser) 4 | 4. Store false as a value 5 | 5. Print all variables in the console -------------------------------------------------------------------------------- /1. Beginners/3. Booleans/challenges/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | huxnProgrammer := true 7 | huxnLoser := false 8 | 9 | fmt.Println(huxnProgrammer) 10 | fmt.Println(huxnLoser) 11 | } -------------------------------------------------------------------------------- /1. Beginners/3. Booleans/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | isGolangPL := true 7 | isHtmlPL := false 8 | fmt.Println(isGolangPL) 9 | fmt.Println(isHtmlPL) 10 | 11 | lightOn := true // Light Is On 12 | lightOn = false // Light Is Off 13 | fmt.Println(lightOn) 14 | } 15 | -------------------------------------------------------------------------------- /1. Beginners/4. Numbers/README.md: -------------------------------------------------------------------------------- 1 | # Operators are used to perform operations on variables and values 2 | 3 | ## Arithmetic Operators 4 | 5 | ### 1. Addition: The + operator adds two operands. For example, x+y. 6 | 7 | ### 2. Subtraction: The - operator subtracts two operands. For example, x-y. 8 | 9 | ### 3. Multiplication: The * operator multiplies two operands. For example, x*y. 10 | 11 | ### 4. Division: The / operator divides the first operand by the second. For example, x/y. 12 | 13 | ### 5. Modulus: Returns the division remainder 14 | 15 | ### 6. Increment: The ++ Increases the value of a variable by 1 16 | 17 | ### 7. Decrement: The -- Decreases the value of a variable by 1 18 | 19 | ```go 20 | 21 | package main 22 | import "fmt" 23 | 24 | func main() { 25 | fmt.Println(2 + 2) // 4 26 | fmt.Println(2 - 2) // 0 27 | fmt.Println(2 * 2) // 4 28 | fmt.Println(2 / 2) // 1 29 | fmt.Println(2 % 2) // 0 30 | } 31 | ``` 32 | 33 | ### Increment 34 | 35 | ```go 36 | 37 | package main 38 | import ("fmt") 39 | 40 | func main() { 41 | x:= 10 42 | x++ // Add one new value (increment) 43 | fmt.Println(x) 44 | } 45 | ``` 46 | 47 | ### Decrement 48 | 49 | ```go 50 | 51 | package main 52 | import ("fmt") 53 | 54 | func main() { 55 | x:= 10 56 | x-- // Remove one new value (decrement) 57 | fmt.Println(x) 58 | } 59 | ``` 60 | 61 | ## Assignment Operators 62 | 63 | ### Assignment operators are used to assign values to variables. 64 | 65 | | Operator | Example | Same As | 66 | | -------- | ------- | ---------- | 67 | | = | x = 5 | x = 5 | 68 | | += | x += 3 | x = x + 3 | 69 | | -= | x -= 3 | x = x - 3 | 70 | | \*= | x \*= 3 | x = x \* 3 | 71 | | /= | x /= 3 | x = x / 3 | 72 | | %= | x %= 3 | x = x % 3 | 73 | -------------------------------------------------------------------------------- /1. Beginners/4. Numbers/challenges/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create variable name (lgNumber) 2 | 2. Store 1000 as a value 3 | 3. Add that variable with itself 4 | 4. Subtract that variable by itself 5 | 5. Multiply that variable with itself 6 | 6. Divide that variable with itself 7 | -------------------------------------------------------------------------------- /1. Beginners/4. Numbers/challenges/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | lgNumber := 1000 7 | fmt.Println(lgNumber) 8 | fmt.Println(lgNumber + lgNumber) 9 | fmt.Println(lgNumber - lgNumber) 10 | fmt.Println(lgNumber * lgNumber) 11 | fmt.Println(lgNumber / lgNumber) 12 | // fmt.Println(lgNumber % 2) 13 | } -------------------------------------------------------------------------------- /1. Beginners/4. Numbers/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // var num1 int = 20000000 7 | var num1 int32 = 20000000 8 | fmt.Println(num1) 9 | 10 | // var num2 float32 = 4545654.5555 11 | var num2 float64 = 4545654.5555 12 | fmt.Println(num2) 13 | 14 | // You can also ommit the types and 15 | // That variable will by default "inferred" it. 16 | specialNumber := 74353.0 17 | fmt.Printf("%T", specialNumber) // checking the type of variable. 18 | 19 | // Arithmetic Operators 👇 20 | fmt.Println(2 + 2) 21 | fmt.Println(2 - 2) 22 | fmt.Println(2 * 2) 23 | fmt.Println(2 / 2) 24 | fmt.Println(2 % 2) 25 | } 26 | -------------------------------------------------------------------------------- /1. Beginners/5. Strings/README.md: -------------------------------------------------------------------------------- 1 | # String Data Type 2 | 3 | ### The string data type is used to store a sequence of characters (text). 4 | 5 | ### String values must be surrounded by double quotes 6 | 7 | ```go 8 | 9 | package main 10 | import "fmt" 11 | 12 | func main() { 13 | fmt.Println("I'm a String data type") 14 | fruit := "Orange" 15 | info := "Hello everyone my name is HuXn and i'm a Golang lover 😊" 16 | yt := "https://www.youtube.com/@huxnwebdev" 17 | fmt.Println(fruit) 18 | fmt.Println(info) 19 | fmt.Println(yt) 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /1. Beginners/5. Strings/challenges/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create variable name (myNameIs) 2 | 2. Store your name side it 3 | 3. Create variable name (info) 4 | 4. Log This message to the console 👇 5 | `My name is (yourName) & I'm (yourAge) years old` 6 | 5. Log everything to the console 7 | -------------------------------------------------------------------------------- /1. Beginners/5. Strings/challenges/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | myNameIs := "HuXn WebDev" 7 | info := `My name is HuXn 8 | & i'm 17 years old.` 9 | fmt.Println(myNameIs) 10 | fmt.Println(info) 11 | } -------------------------------------------------------------------------------- /1. Beginners/5. Strings/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | // --------------------------- 10 | // 1. Using basic string. 11 | name := "HuXn WebDev" 12 | // --------------------------- 13 | 14 | // --------------------------- 15 | // 2. Using Backticks (multiline string). 16 | intro := `Hello 17 | my name is 18 | HuXn` 19 | // --------------------------- 20 | 21 | // --------------------------- 22 | // 3. String Concatenation. 23 | firstName := "HuXn " 24 | lastName := "WebDev" 25 | // --------------------------- 26 | 27 | // --------------------------- 28 | // 4. Concatenation In one line 29 | greetings := "Hello" + " my name is " + "huxn" 30 | // --------------------------- 31 | 32 | // --------------------------- 33 | fmt.Println(name) 34 | fmt.Println(intro) 35 | fmt.Println(firstName + lastName) 36 | fmt.Println(greetings) 37 | // --------------------------- 38 | 39 | // --------------------------- 40 | // 5. Accessing first character from string. 41 | message := "HuXn WebDev" 42 | fmt.Printf("%c\n", message[0]) 43 | 44 | message2 := "HuXn WebDev" 45 | fmt.Printf("%c\n", message2[2]) 46 | 47 | lastMessage := "HuXn WebDev" 48 | fmt.Printf("%c\n", lastMessage[9]) 49 | // --------------------------- 50 | 51 | // --------------------------- 52 | // 6. Checkout the length of the string 53 | fruit := "Mango" 54 | fmt.Println(len(fruit)) 55 | 56 | // 7. Comparing two strings 57 | msg := "one" 58 | msg2 := "one" 59 | fmt.Println(strings.Compare(msg, msg2)) 60 | // -1 because string1 is smaller than string2 61 | // 1 because string2 is greater than string3 62 | // 0 because string1 and string3 are equal 63 | // --------------------------- 64 | 65 | // --------------------------- 66 | // 7. Checking if the string contains certain "character(s)" 67 | findChar := "Golang Programming Language" 68 | fmt.Println(strings.Contains(findChar, "Golang")) // true 69 | fmt.Println(strings.Contains(findChar, "huxn")) // false 70 | // --------------------------- 71 | 72 | // 8. Change the text to lowercase 73 | stringOne := "Hello" 74 | // stringTwo := "bye" 75 | fmt.Println(strings.ToLower(stringOne)) 76 | 77 | // 9. Change the text to UPPERCASE 78 | fmt.Println(strings.ToUpper(stringOne)) 79 | 80 | // RULES 81 | // 1. You cannot use single quotes unlike other programming languages. 82 | // 2. You cannot write your string in multiline using double quotes string, If you still wanna use mutliline string for that you'll have to use backticks `🤚` which will be underneath your escape key and above your tabe key in your keyboard. 83 | 84 | } 85 | -------------------------------------------------------------------------------- /1. Beginners/6. Comparison Operators/README.md: -------------------------------------------------------------------------------- 1 | # Comparison Operators 2 | 3 | ## Comparison operators are used to compare two values 4 | 5 | | Operator | Name | Example | 6 | | -------- | ------------------------ | ------- | 7 | | == | Equal to | x == y | 8 | | != | Not equal | x != y | 9 | | > | Greater than | x > y | 10 | | < | Less than | x < y | 11 | | >= | Greater than or equal to | x >= y | 12 | | <= | Less than or equal to | x <= y | 13 | 14 | ```go 15 | 16 | package main 17 | 18 | import "fmt" 19 | 20 | func main() { 21 | fmt.Println(2 > 2) // false 22 | fmt.Println(2 < 2) // false 23 | fmt.Println(2 >= 2) // true 24 | fmt.Println(2 <= 2) // true 25 | fmt.Println(2 == 2) // true 26 | fmt.Println(2 != 2) // false 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /1. Beginners/6. Comparison Operators/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a variable name (number) 2 | 2. store 20 as a value 3 | 3. Check if the number is greater then 10 4 | 4. Check if the number is less then 10 5 | 5. Check if the number is greater then or equal to 10 6 | 6. Check if the number is less then or equal to 10 7 | 7. Check if the number is equal to number 8 | 8. Check if the number is not equal to number -------------------------------------------------------------------------------- /1. Beginners/6. Comparison Operators/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | var number = 20 6 | 7 | func main() { 8 | fmt.Println(number > 10) 9 | fmt.Println(number < 10) 10 | fmt.Println(number >= 10) 11 | fmt.Println(number <= 10) 12 | fmt.Println(number == number) 13 | fmt.Println(number != number) 14 | } -------------------------------------------------------------------------------- /1. Beginners/6. Comparison Operators/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | numOne := 10 7 | numTwo := 20 8 | fmt.Println(numOne > numTwo) 9 | fmt.Println(numOne < numTwo) 10 | fmt.Println(numOne >= numTwo) 11 | fmt.Println(numOne <= numTwo) 12 | fmt.Println(numOne == numTwo) 13 | fmt.Println(numOne != numTwo) 14 | 15 | fmt.Println(2 > 2) 16 | fmt.Println(2 < 2) 17 | fmt.Println(2 >= 2) 18 | fmt.Println(2 <= 2) 19 | fmt.Println(2 == 2) 20 | fmt.Println(2 != 2) 21 | } 22 | -------------------------------------------------------------------------------- /1. Beginners/7. Logical Operators/README.md: -------------------------------------------------------------------------------- 1 | # Logical Operators 2 | 3 | ## Logical operators are used to determine the logic between variables or values. 4 | 5 | ## 1. Logical and (&&) 6 | 7 | ### Returns true if both statements are true 8 | 9 | ## 2. Logical or (||) 10 | 11 | ### Returns true if one statements is true 12 | 13 | ## 3. Logical not (!) 14 | 15 | ### Reverse the result, returns false if the result is true 16 | 17 | ```go 18 | 19 | package main 20 | 21 | import "fmt" 22 | 23 | func main() { 24 | fmt.Println(true && true) // true 25 | fmt.Println(true && false) // false 26 | 27 | fmt.Println(true || true) // true 28 | fmt.Println(false || false) // false 29 | 30 | fmt.Println(!true) // false 31 | fmt.Println(!false) // true 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /1. Beginners/7. Logical Operators/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create two variables (highIncome, goodCreditScore) & set the values to false 2 | 2. If highIncome OR goodCreditScore the user is eligibleForLoan 3 | 3. If the user is not eligibleForLoan then Application Refused -------------------------------------------------------------------------------- /1. Beginners/7. Logical Operators/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | highIncome := false 7 | goodCreditScore := false 8 | eligibleForLoan := highIncome || goodCreditScore 9 | applicationRefused := !eligibleForLoan 10 | fmt.Println("Eligible:", eligibleForLoan) 11 | fmt.Println("Application Refused:", applicationRefused) 12 | } 13 | -------------------------------------------------------------------------------- /1. Beginners/7. Logical Operators/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println(true && true) 7 | fmt.Println(true && false) 8 | 9 | fmt.Println(true || true) 10 | fmt.Println(false || false) 11 | 12 | fmt.Println(!true) 13 | fmt.Println(!false) 14 | } 15 | -------------------------------------------------------------------------------- /1. Beginners/8. Conditional Statement/README.md: -------------------------------------------------------------------------------- 1 | ## Go Conditions 2 | 3 | ### Conditional statements allow us to control the structure of our program. 4 | 5 | ### There are different ways by which we can control the flow of our program, (If, else if, else) are one of them. 6 | 7 | ### (If, else if, else) statments allow us to make "decisions" while our program is running, They're also called (conditional statments) in programming. 8 | 9 | ```go 10 | // Sudo Syntax 11 | if condition { } 12 | else if condition { } 13 | else { } 14 | ``` 15 | 16 | ```go 17 | // Actual Code 18 | package main 19 | import "fmt" 20 | 21 | func main() { 22 | password := "12345678" 23 | if len(password) > 7 { 24 | fmt.Println("Valid Password") 25 | } else { 26 | fmt.Println("Invalid Password") 27 | } 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /1. Beginners/8. Conditional Statement/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a hour variable and set that to 12 2 | 3 | 2. If the hour is greater then or equal to 6 & hour is less then 12 print("Good Morning") 4 | 5 | 3. If the hour is greater then or equal to 12 & hour is less then 18 print("Good Afternoon") 6 | 7 | 4. If all conditions failed print("Good Evening") -------------------------------------------------------------------------------- /1. Beginners/8. Conditional Statement/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | hour := 12 7 | if hour >= 6 && hour < 12 { 8 | fmt.Println("Good Morning") 9 | } else if hour >= 12 && hour < 18 { 10 | fmt.Println("Good Afternoon") 11 | } else { 12 | fmt.Println("Good Evening") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /1. Beginners/8. Conditional Statement/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // if (true) {} 7 | // else if (true) {} 8 | // else {} 9 | 10 | num := 5 11 | 12 | if num > 5 { 13 | fmt.Println("number is greater then five ") 14 | } else if num < 5 { 15 | fmt.Println("number is less then five") 16 | } else { 17 | fmt.Println("number is equal to five") 18 | } 19 | 20 | password := "12345678" 21 | if len(password) > 7 { 22 | fmt.Println("Valid Password") 23 | } else if password == "" { 24 | fmt.Println("Please provide a password") 25 | } else { 26 | fmt.Println("Invalid Password") 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /1. Beginners/9. For Loop/README.md: -------------------------------------------------------------------------------- 1 | # For Loop 2 | 3 | ## A "For" Loop is used to repeat a specific block of code a known number of times. 4 | 5 | ## For example, if we want to check the grade of every student in the class, we loop from 1 to that number. When the number of times is not known before hand, we use a "While" loop. 6 | 7 | ```go 8 | // Sudo Syntax 9 | for initialExpression; condition; increment { } 10 | ``` 11 | 12 | ```go 13 | package main 14 | import ("fmt") 15 | 16 | func main() { 17 | for i:=0; i < 5; i++ { 18 | fmt.Println(i) 19 | } 20 | } 21 | ``` 22 | 23 | # The continue Statement 24 | 25 | ## The continue statement is used to skip one or more iterations in the loop. It then continues with the next iteration in the loop. 26 | 27 | ```go 28 | package main 29 | import ("fmt") 30 | 31 | func main() { 32 | for i:=0; i < 5; i++ { 33 | if i == 3 { 34 | continue 35 | } 36 | fmt.Println(i) 37 | } 38 | } 39 | ``` 40 | 41 | # The break Statement 42 | 43 | ## The break statement is used to break/terminate the loop execution. 44 | 45 | ```go 46 | package main 47 | import ("fmt") 48 | 49 | func main() { 50 | for i:=0; i < 5; i++ { 51 | if i == 3 { 52 | break 53 | } 54 | fmt.Println(i) 55 | } 56 | } 57 | ``` 58 | 59 | # Nested Loops 60 | 61 | ## Loop inside other loop is known as Nested Loop. 62 | 63 | ```go 64 | package main 65 | 66 | import ( 67 | "fmt" 68 | ) 69 | 70 | func main() { 71 | for i := 0; i < 20; i++ { 72 | fmt.Println("-----OUTER------", i) 73 | for j := 0; j < 10; j++ { 74 | fmt.Println("-----INNER------", j) 75 | } 76 | } 77 | } 78 | 79 | ``` 80 | -------------------------------------------------------------------------------- /1. Beginners/9. For Loop/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Print numbers from 0 through 20 using for loop -------------------------------------------------------------------------------- /1. Beginners/9. For Loop/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | for i := 0; i <= 20; i++ { 7 | fmt.Println("Count: ", i) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /1. Beginners/9. For Loop/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | for x := 0; x < 20; x++ { 7 | fmt.Println(x) 8 | } 9 | 10 | for i := 0; i <= 10; i++ { 11 | fmt.Println("Hello World", i) 12 | } 13 | 14 | for j := 1; j <= 10; j++ { 15 | fmt.Println(j) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2. Intermediate/1. Functions/README.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | ### A function is a block of statements that can be used repeatedly in a program. 4 | 5 | ### Functions are not executed immediately. They are "saved for later use", and will be executed when they are called. 6 | 7 | ```go 8 | package main 9 | import "fmt" 10 | 11 | // My Own Function 12 | func printName(username string) { 13 | fmt.Println(username) 14 | } 15 | 16 | func main() { 17 | printName("HuXn") 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /2. Intermediate/1. Functions/challenge/challenge.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | greet("HuXn ", "WebDev") 7 | double(1,2,3) 8 | ppls := []string{"HuXn", "John", "Jordan"} 9 | itter(ppls) 10 | } 11 | 12 | func greet(firstName string, lastName string) (string, string) { 13 | return "Hello", firstName + lastName 14 | } 15 | 16 | func double(nums ...int) { 17 | for _, v := range nums { 18 | fmt.Println(v*2) 19 | } 20 | } 21 | 22 | func itter(slice []string) { 23 | for i, v := range slice { 24 | fmt.Println(i, "-", v) 25 | } 26 | } -------------------------------------------------------------------------------- /2. Intermediate/1. Functions/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create function name (greet) which will take two parameters (firstName, lastName) and just greet to the user by their first name and last name. 2 | 3 | 2. Create function name (double) which will take unlimited amount of parameters and just double that. 4 | 5 | 3. Create function name (itter) which will take slice, just iterate over the slice print the index and the value, which is provided as a slice. -------------------------------------------------------------------------------- /2. Intermediate/1. Functions/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | hello() 7 | greet("John") 8 | showNumbers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) 9 | showUsers("HuXn", "Alex", "John", "Jordan") 10 | } 11 | 12 | func hello() { 13 | fmt.Println("Hello") 14 | } 15 | 16 | func greet(name string) { 17 | fmt.Println("Hello", name) 18 | } 19 | 20 | func showNumbers(numbers ...int) { 21 | fmt.Println(numbers) 22 | } 23 | 24 | func showUsers(s ...string) { 25 | for i, v := range s { 26 | fmt.Println(i, "-", v) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2. Intermediate/2. Function Expression/README.md: -------------------------------------------------------------------------------- 1 | # Function Expression 2 | 3 | ### When we store a function inside a "variable" that function is known as Function Expression. 4 | 5 | ```go 6 | package main 7 | 8 | import "fmt" 9 | 10 | func main() { 11 | add := func(num1 int, num2 int) int { 12 | return num1 + num2 13 | } 14 | 15 | res := add(10, 20) 16 | fmt.Println(res) 17 | } 18 | 19 | ``` 20 | -------------------------------------------------------------------------------- /2. Intermediate/2. Function Expression/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a function and store it in (double) variable, which will take unlimited amount of parameters and double them. -------------------------------------------------------------------------------- /2. Intermediate/2. Function Expression/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | double := func(nums ...int) { 7 | for _, v := range nums { 8 | fmt.Println(v*2) 9 | } 10 | } 11 | double(1,2,3,4) 12 | } 13 | -------------------------------------------------------------------------------- /2. Intermediate/2. Function Expression/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | f := func() { 7 | fmt.Println("Function Expression") 8 | } 9 | f() 10 | } 11 | -------------------------------------------------------------------------------- /2. Intermediate/3. Anonymous Functions/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | Create anonymous function which will take unlimited amount of parameters and double them. -------------------------------------------------------------------------------- /2. Intermediate/3. Anonymous Functions/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | func(nums ...int) { 7 | for _, v := range nums { 8 | fmt.Println(v * 2) 9 | } 10 | }(1, 2, 3, 4) 11 | } 12 | -------------------------------------------------------------------------------- /2. Intermediate/3. Anonymous Functions/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | func() { 7 | fmt.Println("Anonymous Function") 8 | }() 9 | } 10 | -------------------------------------------------------------------------------- /2. Intermediate/4. Methods/README.md: -------------------------------------------------------------------------------- 1 | # Methods 2 | 3 | ### A method is a function associated with a particular type. It is a way to define behavior for a specific type. In Go, methods are declared with a receiver, which is a special type of parameter that appears in the method signature. The receiver indicates on which type the method operates. 4 | 5 | ```go 6 | package main 7 | 8 | import "fmt" 9 | 10 | // Define a type named "Person" 11 | type Person struct { 12 | FirstName string 13 | LastName string 14 | } 15 | 16 | // Define a method named "FullName" for the type "Person" 17 | func (p Person) FullName() string { 18 | return p.FirstName + " " + p.LastName 19 | } 20 | 21 | func main() { 22 | // Create a Person instance 23 | person := Person{FirstName: "John", LastName: "Doe"} 24 | 25 | // Call the method on the Person instance 26 | fullName := person.FullName() 27 | 28 | // Print the result 29 | fmt.Println("Full Name:", fullName) 30 | } 31 | 32 | 33 | ``` 34 | -------------------------------------------------------------------------------- /2. Intermediate/4. Methods/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create human struct which will take the following properties 2 | [gender string] 3 | [fullName string] 4 | [age int] 5 | friends 6 | 7 | 2. Create friends struct which will take the following properties 8 | [justFriends int] 9 | [bestFriend string] 10 | 11 | 3. Create method (printInfo) which will take "human" as a parameter 12 | 13 | 4. Log this message 👇 14 | "My name is", (YOUR NAME), "Gender:", (YOUR GENDER), "Age:", (YOUR AGE), "I have", (YOUR FRIENDS), "Friends but my best friend is", (YOUR BEST FRIEND) 15 | 16 | 5. Create instance of human struct and provide your favorite values to each property 17 | 18 | 6. Call printInfo method on human -------------------------------------------------------------------------------- /2. Intermediate/4. Methods/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type human struct { 6 | gender string 7 | fullName string 8 | age int 9 | friends 10 | } 11 | 12 | type friends struct { 13 | justFriends int 14 | bestFriend string 15 | } 16 | 17 | // Method 18 | func (h human) printInfo() { 19 | fmt.Println("My name is", h.fullName, "Gender:", h.gender, "Age:", h.age, "I have", h.justFriends, "Friends but my best friend is", h.bestFriend) 20 | } 21 | 22 | func main() { 23 | huxn := human{ 24 | gender: "male", 25 | fullName: "HuXn WebDev", 26 | age: 17, 27 | friends: friends{ 28 | justFriends: 20, 29 | bestFriend: "John", 30 | }, 31 | } 32 | huxn.printInfo() 33 | } 34 | -------------------------------------------------------------------------------- /2. Intermediate/4. Methods/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type person struct { 6 | gender string 7 | firstName string 8 | lastName string 9 | age int 10 | profession string 11 | isMarried bool 12 | } 13 | 14 | func (p person) printInfo() { 15 | fmt.Println("I'm", p.firstName, p.lastName, "Gender:", p.gender, "Age:", p.age, "Profession:", p.profession, "Married", p.isMarried) 16 | } 17 | 18 | func main() { 19 | huxn := person{ 20 | gender: "Male", 21 | firstName: "HuXn", 22 | lastName: "WebDev", 23 | age: 17, 24 | profession: "Programming", 25 | isMarried: false, 26 | } 27 | huxn.printInfo() 28 | } 29 | -------------------------------------------------------------------------------- /2. Intermediate/5. Callback Functions/README.md: -------------------------------------------------------------------------------- 1 | # Callback Functions 2 | 3 | ### If a function is passed as an argument to another function, then such types of functions are known as a Higher-Order function. This passing function as an argument is also known as a callback function or first-class function in the Go language. 4 | 5 | ```go 6 | package main 7 | import "fmt" 8 | 9 | func addName(name string, callback func(string)) { 10 | callback(name) 11 | } 12 | 13 | func main() { 14 | addName("HuXn", func(nm string) { 15 | fmt.Printf("hi may name is %v \n", nm) 16 | }) 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /2. Intermediate/5. Callback Functions/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Creat a function which will just return "hello" 2 | 3 | 2. Creat a function which will just return "World" 4 | 5 | 3. Create a function (run) which will take function as an parameter and then call that "parameter function" inside the run function. -------------------------------------------------------------------------------- /2. Intermediate/5. Callback Functions/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | run(hello) 9 | run(world) 10 | } 11 | 12 | func hello() { 13 | fmt.Println("Hello") 14 | } 15 | 16 | func world() { 17 | fmt.Println("World!") 18 | } 19 | 20 | func run(f func()) { 21 | f() 22 | } -------------------------------------------------------------------------------- /2. Intermediate/5. Callback Functions/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func addName(name string, callback func(string)) { 6 | callback(name) 7 | } 8 | 9 | func main() { 10 | addName("HuXn", func(nm string) { 11 | fmt.Printf("Hi may name is %v \n", nm) 12 | }) 13 | } 14 | -------------------------------------------------------------------------------- /2. Intermediate/6. Defer Keyword/README.md: -------------------------------------------------------------------------------- 1 | # Defer Keyword 2 | 3 | ### The defer keyword is used to delay the execution of a function or a statement until the nearby function returns. In simple words, defer will move the execution of the statement to the very end inside a function. 4 | 5 | ```go 6 | package main 7 | import "fmt" 8 | 9 | func greet() { 10 | defer fmt.Println("World") 11 | fmt.Println("Hello") 12 | } 13 | 14 | func main() { 15 | greet() 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /2. Intermediate/6. Defer Keyword/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a function (multiply) which will take two parameters and multiply them 2 | 3 | 2. Create a function (printMessage) which will just print("Hello HuXn") 4 | 5 | 3. In the main function call multiply function with defer keyword, underneath that call printMessage function and see which function runs first. -------------------------------------------------------------------------------- /2. Intermediate/6. Defer Keyword/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func multiply(num1, num2 int) { 6 | fmt.Println("Result: ", num1 * num2) 7 | } 8 | 9 | func printMessage() { 10 | fmt.Println("Hello, HuXn") 11 | } 12 | 13 | func main() { 14 | defer multiply(23, 56) 15 | printMessage() 16 | } -------------------------------------------------------------------------------- /2. Intermediate/6. Defer Keyword/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func greet() { 6 | defer fmt.Println("World") 7 | fmt.Println("Hello") 8 | } 9 | 10 | func main() { 11 | greet() 12 | } 13 | 14 | -------------------------------------------------------------------------------- /2. Intermediate/7. Scopes/README.md: -------------------------------------------------------------------------------- 1 | # Scope 2 | 3 | ### Think of scope as the visibility or accessibility of things (like variables or functions) in your code. It's like where things are known or can be used. 4 | 5 | ### 1. Block Scope 6 | 7 | #### Imagine your code as a series of blocks, like paragraphs in a story. 8 | 9 | #### Variables and functions created inside a block are known only within that block. 10 | 11 | ```go 12 | func main() { 13 | // Inside main's block 14 | var x int = 10 15 | fmt.Println(x) // Can use x here 16 | 17 | if true { 18 | // Inside if's block 19 | var y int = 20 20 | fmt.Println(y) // Can use y here 21 | } 22 | 23 | // Can't use y here, it's outside its block 24 | } 25 | ``` 26 | 27 | ### 2. Function Scope 28 | 29 | #### Functions have their own scope. Variables defined inside a function are known only within that function. 30 | 31 | ```go 32 | func myFunction() { 33 | // Inside myFunction's block 34 | var z int = 30 35 | fmt.Println(z) // Can use z here 36 | } 37 | 38 | // Can't use z here, it's outside myFunction's block 39 | ``` 40 | 41 | ### 3. Package Scope 42 | 43 | #### Variables and functions defined at the top level of a package have a wider scope. 44 | 45 | #### They can be used across multiple files within the same package. 46 | 47 | ```go 48 | package main 49 | 50 | // Outside any function, package scope 51 | var globalVariable int = 50 52 | 53 | func main() { 54 | // Can use globalVariable here 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /2. Intermediate/7. Scopes/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | var name = "HuXn" // Global 6 | 7 | func main() { 8 | m := 200 // Local Scope Variable 9 | fmt.Println(name) 10 | showName() 11 | fmt.Println(m) 12 | } 13 | 14 | // Global Scope Function 15 | func showName() { 16 | fmt.Println(name) 17 | } 18 | -------------------------------------------------------------------------------- /2. Intermediate/8. Pointers/README.md: -------------------------------------------------------------------------------- 1 | # Pointers 2 | 3 | ### A pointer in Go is a variable that stores the memory address of another variable. By using pointers, you can indirectly access and modify the value of the variable whose address is stored in the pointer. 4 | 5 | #### You can create a pointer using the \* (asterisk) symbol. 6 | 7 | #### The & (ampersand) symbol is used to obtain the memory address of a variable 8 | 9 | ```go 10 | package main 11 | 12 | import "fmt" 13 | 14 | func main() { 15 | // Declare a variable 16 | x := 42 17 | 18 | // Create a pointer that stores the memory address of x 19 | var pointerToX *int = &x 20 | 21 | // Print the value and memory address of x 22 | fmt.Println("Value of x:", x) 23 | fmt.Println("Memory address of x:", &x) 24 | 25 | // Print the value and memory address stored in the pointer 26 | fmt.Println("Value pointed to by pointerToX:", *pointerToX) 27 | fmt.Println("Memory address stored in pointerToX:", pointerToX) 28 | } 29 | 30 | ``` 31 | -------------------------------------------------------------------------------- /2. Intermediate/8. Pointers/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create two variables (apple, orange) & print their address 2 | 2. Swap their values 3 | 3. Print values -------------------------------------------------------------------------------- /2. Intermediate/8. Pointers/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | apple := "apple" 7 | orange := "orange" 8 | 9 | fmt.Println(&apple) 10 | fmt.Println(&orange) 11 | 12 | fmt.Println(apple) 13 | fmt.Println(orange) 14 | 15 | swap := *&apple 16 | apple = orange 17 | orange = swap 18 | fmt.Println("--------------") 19 | fmt.Println(*&apple) 20 | fmt.Println(*&orange) 21 | } 22 | -------------------------------------------------------------------------------- /2. Intermediate/8. Pointers/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // Declare a variable 7 | x := 42 8 | 9 | // Create a pointer that stores the memory address of x 10 | var pointerToX *int = &x 11 | 12 | // Print the value and memory address of x 13 | fmt.Println("Value of x:", x) 14 | fmt.Println("Memory address of x:", &x) 15 | 16 | // Print the value and memory address stored in the pointer 17 | fmt.Println("Value pointed to by pointerToX:", *pointerToX) 18 | fmt.Println("Memory address stored in pointerToX:", pointerToX) 19 | } 20 | 21 | // -------------------------- 22 | // Example 2 23 | 24 | // package main 25 | 26 | // import "fmt" 27 | 28 | // func main() { 29 | // address := 10 30 | // fmt.Println(address) 31 | // fmt.Println(&address) 32 | 33 | // fmt.Printf("%T\n", address) 34 | // fmt.Printf("%T\n", &address) 35 | 36 | // value := &address 37 | // fmt.Println(*&value) 38 | // } -------------------------------------------------------------------------------- /2. Intermediate/9. Panic/README.md: -------------------------------------------------------------------------------- 1 | # panic() 2 | 3 | ### Similar to exceptions raised at runtime when an error is encountered. panic() is either raised by the program itself when an unexpected error occurs or the programmer throws the exception on purpose for handling particular errors. 4 | 5 | ```go 6 | package main 7 | 8 | func employee(name *string, age int){ 9 | if age > 65{ 10 | panic("Age cannot be greater than retirement age") 11 | } 12 | 13 | } 14 | 15 | func main() { 16 | empName := "Samia" 17 | age := 75 18 | employee(&empName, age) 19 | } 20 | ``` 21 | -------------------------------------------------------------------------------- /2. Intermediate/9. Panic/challenge/instructions.txt: -------------------------------------------------------------------------------- 1 | 1. Create a function (checkPassword) which will take password as a parameter 2 | 3 | 2. Inside that function check if the password is less then 8 show panic message 4 | panic("Password should be 8 characters") 5 | 6 | 3. Otherwise print 7 | fmt.Println("Valid Password :)") 8 | 9 | 4. Call checkPassword function in main func. -------------------------------------------------------------------------------- /2. Intermediate/9. Panic/challenge/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func checkPassword(password string) { 6 | if len(password) < 8 { 7 | panic("Password should be 8 characters") 8 | } else { 9 | fmt.Println("Valid Password :)") 10 | } 11 | } 12 | 13 | func main() { 14 | // checkPassword("12345678") // Valid Password 15 | checkPassword("125as") // Panic :( 16 | } 17 | -------------------------------------------------------------------------------- /2. Intermediate/9. Panic/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func employee(name *string, age int) { 4 | if age > 65 { 5 | panic("Age cannot be greater than retirement age") 6 | } 7 | } 8 | 9 | func main() { 10 | empName := "John" 11 | age := 75 12 | employee(&empName, age) 13 | } -------------------------------------------------------------------------------- /3. Advance/1. Interfaces/1. example-one.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // Animal interface represents an animal that can provide information 6 | type Animal interface { 7 | GetInfo() string 8 | } 9 | 10 | // Cat struct represents a cat 11 | type Cat struct { 12 | Name string 13 | Color string 14 | } 15 | 16 | // Implement the Animal interface for Cat 17 | func (c Cat) GetInfo() string { 18 | return fmt.Sprintf("Cat: %s, Color: %s", c.Name, c.Color) 19 | } 20 | 21 | // Dog struct represents a dog 22 | type Dog struct { 23 | Name string 24 | Breed string 25 | } 26 | 27 | // Implement the Animal interface for Dog 28 | func (d Dog) GetInfo() string { 29 | return fmt.Sprintf("Dog: %s, Breed: %s", d.Name, d.Breed) 30 | } 31 | 32 | // Function to print information about an animal 33 | func printAnimalInfo(animal Animal) { 34 | fmt.Println(animal.GetInfo()) 35 | } 36 | 37 | func main() { 38 | // Create instances of Cat and Dog 39 | cat := Cat{Name: "Whiskers", Color: "Gray"} 40 | dog := Dog{Name: "Buddy", Breed: "Labrador"} 41 | 42 | // Print information about Cat using the interface 43 | printAnimalInfo(cat) 44 | 45 | // Print information about Dog using the interface 46 | printAnimalInfo(dog) 47 | } 48 | 49 | -------------------------------------------------------------------------------- /3. Advance/1. Interfaces/2. example-two.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // Define a simple interface named 'Describer' 6 | type Describer interface { 7 | Describe() string 8 | } 9 | 10 | // Implement the interface for a 'Person' 11 | type Person struct { 12 | Name string 13 | } 14 | 15 | // Implement the 'Describe' method for 'Person' 16 | func (p Person) Describe() string { 17 | return "Hi, I'm " + p.Name 18 | } 19 | 20 | // Implement the interface for a 'Car' 21 | type Car struct { 22 | Model string 23 | } 24 | 25 | // Implement the 'Describe' method for 'Car' 26 | func (c Car) Describe() string { 27 | return "This is a " + c.Model + " car" 28 | } 29 | 30 | // Function to display description using the interface 31 | func displayDescription(d Describer) { 32 | fmt.Println(d.Describe()) 33 | } 34 | 35 | func main() { 36 | // Create instances of Person and Car 37 | person := Person{Name: "Alice"} 38 | car := Car{Model: "Toyota"} 39 | 40 | // Use the Describe method through the Describer interface 41 | displayDescription(person) 42 | displayDescription(car) 43 | } 44 | -------------------------------------------------------------------------------- /3. Advance/1. Interfaces/3. example-three.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "log" 4 | 5 | // Interface 6 | type Human interface { 7 | // Method Structure 8 | UserName() string 9 | Profession() string 10 | } 11 | 12 | // Structs 13 | type User1 struct { 14 | Age int 15 | Gender string 16 | } 17 | 18 | type User2 struct { 19 | Gender string 20 | Age int 21 | Location string 22 | } 23 | 24 | 25 | // Methods 26 | func (j User1) Profession() string { 27 | return "Front-End Developer" 28 | } 29 | 30 | func (j User1) UserName() string { 31 | return "John" 32 | } 33 | 34 | func (a User2) Profession() string { 35 | return "Back-End Developer" 36 | } 37 | 38 | func (a User2) UserName() string { 39 | return "Lara" 40 | } 41 | 42 | func main() { 43 | // Instance of structs 44 | john := User1 { 45 | Gender: "male", 46 | Age: 20, 47 | } 48 | 49 | PrintInfo(john) 50 | 51 | Lara := User2 { 52 | Gender: "female", 53 | Age: 19, 54 | Location: "USA", 55 | } 56 | 57 | PrintInfo(Lara) 58 | } 59 | 60 | // Info Function 61 | func PrintInfo(h Human) { 62 | log.Println("My name is a ", h.UserName(), "and i am a professional", h.Profession()) 63 | } 64 | -------------------------------------------------------------------------------- /3. Advance/1. Interfaces/README.md: -------------------------------------------------------------------------------- 1 | # Interface 2 | 3 | ### An interface is a type that specifies a set of method signatures. It defines a contract for what methods a type must have, but it does not provide the implementation for those methods. Instead, the implementation is provided by concrete types that satisfy the interface. 4 | 5 | ```go 6 | 7 | package main 8 | 9 | import "fmt" 10 | 11 | // Define an interface named Speaker 12 | type Speaker interface { 13 | Speak() string 14 | } 15 | 16 | // Implement the Speaker interface for Dog 17 | type Dog struct{} 18 | 19 | func (d Dog) Speak() string { 20 | return "Woof!" 21 | } 22 | 23 | // Implement the Speaker interface for Cat 24 | type Cat struct{} 25 | 26 | func (c Cat) Speak() string { 27 | return "Meow!" 28 | } 29 | 30 | // Function that takes any type implementing the Speaker interface 31 | func announce(speaker Speaker) { 32 | fmt.Println("The speaker says:", speaker.Speak()) 33 | } 34 | 35 | func main() { 36 | // Create instances of Dog and Cat 37 | dog := Dog{} 38 | cat := Cat{} 39 | 40 | // Use the announce function with different types 41 | announce(dog) // The speaker says: Woof! 42 | announce(cat) // The speaker says: Meow! 43 | } 44 | 45 | 46 | ``` 47 | -------------------------------------------------------------------------------- /3. Advance/2. Generics/README.md: -------------------------------------------------------------------------------- 1 | # Generics 2 | 3 | ### Generics in Go provide a way to write functions and data structures that can work with any data type while maintaining type safety 4 | 5 | ### 1. Generics in Go involve defining functions or data structures with type parameters. 6 | 7 | ### 2. Type parameters are specified inside square brackets ([]) before the function or type signature. 8 | 9 | ```go 10 | package main 11 | 12 | import "fmt" 13 | 14 | // PrintSlice is a generic function that prints elements of any slice. 15 | func PrintSlice[T any](s []T) { 16 | for _, v := range s { 17 | fmt.Println(v) 18 | } 19 | } 20 | 21 | func main() { 22 | // Example with integers 23 | intSlice := []int{1, 2, 3, 4, 5} 24 | PrintSlice(intSlice) 25 | 26 | // Example with strings 27 | stringSlice := []string{"apple", "banana", "cherry"} 28 | PrintSlice(stringSlice) 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /3. Advance/2. Generics/index.go: -------------------------------------------------------------------------------- 1 | // Without Generics 2 | // package main 3 | 4 | // import "fmt" 5 | 6 | // // Function printNumber 7 | // func printNumber(item, defaultValue int) (int, int) { 8 | // return item, defaultValue 9 | // } 10 | 11 | // // Function printString 12 | // func printString(item, defaultValue string) (string, string) { 13 | // return item, defaultValue 14 | // } 15 | 16 | // // Function printBoolean 17 | // func printBoolean(item, defaultValue bool) (bool, bool) { 18 | // return item, defaultValue 19 | // } 20 | 21 | // func main() { 22 | // // Example usage 23 | // num, _ := printNumber(42, 0) 24 | // fmt.Println(num) // Outputs: (42, 0) 25 | 26 | // str, _ := printString("hello", "world") 27 | // fmt.Println(str) // Outputs: (hello, world) 28 | 29 | // boolean, _ := printBoolean(true, false) 30 | // fmt.Println(boolean) // Outputs: (true, false) 31 | // } 32 | // ----------------------------------- 33 | 34 | // With Generics 35 | package main 36 | 37 | import "fmt" 38 | 39 | // generic function printItem 40 | func printItem[T any](item, defaultValue T) (T, T) { 41 | return item, defaultValue 42 | } 43 | 44 | func main() { 45 | // Example usage 46 | num, _ := printItem(42, 0) 47 | fmt.Println(num) // Outputs: (42, 0) 48 | 49 | str, _ := printItem("hello", "world") 50 | fmt.Println(str) // Outputs: (hello, world) 51 | 52 | boolean, _ := printItem(true, false) 53 | fmt.Println(boolean) // Outputs: (true, false) 54 | } 55 | 56 | // ----------------------------------- 57 | // --- Example 2 --- 58 | 59 | // package main 60 | 61 | // import "fmt" 62 | 63 | // // A generic function to compare two values of any type 64 | // func Compare[T comparable](a, b T) bool { 65 | // return a == b 66 | // } 67 | 68 | // func main() { 69 | // // Compare integers 70 | // resultInt := Compare(10, 20) 71 | // fmt.Println("Are the integers equal?", resultInt) 72 | 73 | // // Compare strings 74 | // resultStr := Compare("hello", "world") 75 | // fmt.Println("Are the strings equal?", resultStr) 76 | // } 77 | -------------------------------------------------------------------------------- /3. Advance/3. Goroutines/README.md: -------------------------------------------------------------------------------- 1 | # Goroutines 2 | 3 | ### Goroutine is a lightweight, independently running function that allows concurrent execution in a program. It's like a mini-thread managed by the Go runtime, making it easy to run multiple tasks simultaneously. Goroutines are a key feature for concurrent programming in the Go language. 4 | 5 | # Characteristics 6 | 7 | ### 1. Concurrency: Goroutines let you do multiple things at the same time in a straightforward way. It's like juggling several tasks without dropping any balls. 8 | 9 | ### 2. Low Overhead: Goroutines are like very lightweight helpers that don't take up much space. You can have lots of them in your program without it getting too heavy. 10 | 11 | ### 3. Concurrency with Share Memory: Goroutines communicate and synchronize using shared memory (via channels), making it easy to coordinate the execution of concurrent tasks. 12 | 13 | ### 4. Language-Level Support: Goroutines are like little workers provided by the Go language itself. You don't have to worry about complicated details because the Go language helps you manage them easily. It's like having a team of workers that already know how to cooperate. 14 | 15 | ``` 16 | go funcName() 17 | 18 | ``` 19 | -------------------------------------------------------------------------------- /3. Advance/3. Goroutines/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func printNumbers() { 9 | for i := 1; i <= 5; i++ { 10 | time.Sleep(100 * time.Millisecond) 11 | fmt.Printf("%d ", i) 12 | } 13 | } 14 | 15 | func main() { 16 | // Launching a goroutine 17 | go printNumbers() 18 | 19 | // This line will be executed concurrently with the goroutine 20 | fmt.Println("This is the main function.") 21 | 22 | // Sleeping to allow the goroutine to complete 23 | time.Sleep(1 * time.Second) 24 | } 25 | -------------------------------------------------------------------------------- /3. Advance/4. Channels/1. simple-example.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func sendData(ch chan<- int) { 6 | ch <- 42 7 | } 8 | 9 | func main() { 10 | // Creating an unbuffered channel 11 | ch := make(chan int) 12 | 13 | // Launching a goroutine to send data into the channel 14 | go sendData(ch) 15 | 16 | // Receiving data from the channel 17 | value := <-ch 18 | 19 | // Printing the received value 20 | fmt.Println("Received:", value) 21 | } 22 | -------------------------------------------------------------------------------- /3. Advance/4. Channels/2. buffered and unbuffered.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // Unbuffered channel 7 | unbufferedCh := make(chan int) 8 | 9 | // Buffered channel with a capacity of 2 10 | bufferedCh := make(chan string, 2) 11 | 12 | // Sending data into the unbuffered channel 13 | go func() { 14 | unbufferedCh <- 42 15 | }() 16 | 17 | // Sending data into the buffered channel 18 | go func() { 19 | bufferedCh <- "Hello" 20 | bufferedCh <- "World" 21 | close(bufferedCh) 22 | }() 23 | 24 | // Receiving data from the unbuffered channel 25 | value := <-unbufferedCh 26 | fmt.Println("Received from unbuffered channel:", value) 27 | 28 | // Receiving data from the buffered channel 29 | for msg := range bufferedCh { 30 | fmt.Println("Received from buffered channel:", msg) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /3. Advance/4. Channels/README.md: -------------------------------------------------------------------------------- 1 | # Channels 2 | 3 | ### Channels in Go are like communication pipes between different parts of your program. They let different pieces of your code talk to each other by sending and receiving messages. It's like passing notes or messages between friends to coordinate what needs to be done. 4 | 5 | ### Imagine you have two friends working on a project. One friend can put notes in the channel, and the other friend can pick up those notes. This helps them share information and work together without getting in each other's way. That's what channels do in Go—they help different parts of your program communicate smoothly. 6 | 7 | #### Creating a channel is like making a special mailbox for messages. You can use the make function to create this mailbox. It's like setting up a mailbox with a specific type of messages it can hold. 8 | 9 | ```go 10 | // Creating a channel for sending and receiving messages of type int 11 | myChannel := make(chan int) 12 | 13 | ``` 14 | 15 | ```go 16 | // Sending the number 20 into the channel 17 | myChannel <- 20 18 | ``` 19 | 20 | ```go 21 | // Receiving a message from the channel and storing it in the variable 'result' 22 | result := <-myChannel 23 | ``` 24 | 25 | # Unbuffered Channels 26 | 27 | ### 1. An unbuffered channel has a capacity of 0. 28 | 29 | ### 2. Each send operation on an unbuffered channel blocks until there is a corresponding receive operation, and vice versa. 30 | 31 | ### 3. This creates a direct, synchronous communication between the sender and the receiver. 32 | 33 | # Buffered Channels 34 | 35 | ### 1. A buffered channel has a specified capacity greater than 0. 36 | 37 | ### 2. It allows multiple values to be sent into the channel without an immediate corresponding receiver. 38 | 39 | ### 3. Send operations on a buffered channel block only when the buffer is full, and receive operations block only when the buffer is empty. 40 | -------------------------------------------------------------------------------- /3. Advance/5. waitGroups/README.md: -------------------------------------------------------------------------------- 1 | # Wait Groups 2 | 3 | ### Imagine you have a group of friends working on different tasks, and you want to make sure everyone finishes before moving on. A wait group is like a coordinator or a counter that helps you wait for all your friends to complete their tasks. 4 | 5 | #### Add Friends to the Group: 6 | 7 | ```go 8 | // You add your friends (goroutines) to the wait group before they start their tasks. 9 | var wg sync.WaitGroup 10 | ``` 11 | 12 | #### Friends Start Tasks: 13 | 14 | ```go 15 | // Your friends start working on their tasks (goroutines). 16 | wg.Add(1) // Adding one friend to the group 17 | go func() { 18 | // Friend's task 19 | defer wg.Done() // When the task is done, tell the wait group 20 | }() 21 | ``` 22 | 23 | #### Wait for Friends to Finish: 24 | 25 | ```go 26 | // You wait for your friends to finish their tasks. 27 | 28 | wg.Wait() // Wait until all friends are done 29 | ``` 30 | 31 | #### The wait group is like a helpful friend that keeps track of tasks. When a friend finishes their task, they say, "I'm done," and the wait group listens. You wait until all your friends say they're done before moving on. It helps ensure that everything is completed before you proceed with the next steps in your program. 32 | -------------------------------------------------------------------------------- /3. Advance/5. waitGroups/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | func printMessage(wg *sync.WaitGroup, msg string) { 9 | defer wg.Done() // Decrement the WaitGroup counter when done 10 | fmt.Println(msg) 11 | } 12 | 13 | func main() { 14 | var wg sync.WaitGroup // Create a WaitGroup 15 | 16 | wg.Add(3) // Add the number of Goroutines you're waiting for 17 | 18 | go printMessage(&wg, "Hello") 19 | go printMessage(&wg, "Go") 20 | go printMessage(&wg, "WaitGroup") 21 | 22 | wg.Wait() // Wait for all Goroutines to finish 23 | 24 | fmt.Println("All messages printed.") 25 | } 26 | -------------------------------------------------------------------------------- /3. Advance/6. Select/README.md: -------------------------------------------------------------------------------- 1 | # Select 2 | 3 | ### The select statement is used to handle multiple channels in a non-blocking way. It provides a way to wait on multiple communication operations simultaneously and execute the first case that is ready. 4 | 5 | ### Imagine you have several friends sending you messages, and you want to read whatever message comes first. The select statement is like a way to check all your messages and respond to the first one that arrives. 6 | 7 | ```go 8 | // Whichever friend's message arrives first is the one you respond to. 9 | select { 10 | case message1 := <-channel1: 11 | fmt.Println("Received from friend 1:", message1) 12 | case number := <-channel2: 13 | fmt.Println("Received from friend 2:", number) 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /3. Advance/6. Select/index.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | ch1 := make(chan string) 10 | ch2 := make(chan string) 11 | 12 | go func() { 13 | time.Sleep(2 * time.Second) 14 | ch1 <- "Message from Channel 1" 15 | }() 16 | 17 | go func() { 18 | time.Sleep(4 * time.Second) 19 | ch2 <- "Message from Channel 2" 20 | }() 21 | 22 | // Use select to wait for either ch1 or ch2 23 | select { 24 | case msg1 := <-ch1: 25 | fmt.Println("Received from Channel 1:", msg1) 26 | case msg2 := <-ch2: 27 | fmt.Println("Received from Channel 2:", msg2) 28 | case <-time.After(5 * time.Second): 29 | fmt.Println("No communication ready") 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HuXn-WebDev/Golang-Complete-Course/9b50fe03ea8507d105a5a6ac46d46173da6b188c/README.md -------------------------------------------------------------------------------- /thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HuXn-WebDev/Golang-Complete-Course/9b50fe03ea8507d105a5a6ac46d46173da6b188c/thumb.png --------------------------------------------------------------------------------