go run <file_name1>, <file_name1>
go run .
go build
Variables in Go
- Normal variable
var a int = 10
- Shorthand
a := 10
For Loop Variants
- Normal For Loop
for i := 0; i < 10; i++ { // do something }
- While Loop Style - For Loop
i := 0 for i < 10 { // do something i++ }
- Infinite Loop
for { // do something } // OR for true { // do something }
Return Multiple values from a Method
- Code example
func go() (int error) { return 0, nil } func main() { i, err := foo() if err !=nil { panic(err) } println(i) }
Make is only used with a slice, map and channel(chan)
Make initializes the underlying datastuctures for above mentioned DS
```
func main() {
type TypeStruct struct {
Name string
}
t := new(TestStruct) // type *TestStruct - Create an Object with Zero values of the variables
var v TestStruct // type TestStruct
}
```
Type function: https://www.youtube.com/watch?v=pR5nQ6N6-YA
https://www.youtube.com/watch?v=uiUCIz-3CWM https://www.youtube.com/watch?v=kaZOXRqFPCw https://www.youtube.com/watch?v=LSzR0VEraWw https://go.dev/tour/list
Section 8: concurrency/waitGroups(making the main thread wait)/mutex(remove race condition)/channels(passing data to routines) ?
Returning a function or array of functions from a function New vs Make