These are the key takeaways and point to revise/reiterate of the learning from Go Tutorial.
-
fmt --> String format
- Sprintf --> Parse string with variables
- Println --> Print to console
-
log --> Print console logs
- SetPrefix --> set prefix for log messages
- SetFlags --> Timestamps?
-
errors --> Generate error messages + ?
- New --> create new error with a message
-
math/rand --> Generate random numbers?
-
time --> Time operations like Now()
-
testing --> Builtin testing package
- *testing.T pointer
-
regexp -->
- want how is this used?
- MustCompile()
- Back ticks - purpose?
- MatchString() -- Check if a string that matches regex is found in the argument passed
:= can be used to declare and assign a variable
Can be used to validate if a variable is empty?
-
Declaration:
[]string{ "item1", "item2", "item3", }
Note: Comma after last item in array
-
init is called after all the variable declarations in the package have evaluated their initializers, and those are evaluated only after all the imported packages have been initialized.
func init() { if user == "" { log.Fatal("$USER not set") } if home == "" { home = "/home/" + user } if gopath == "" { gopath = home + "/go" } // gopath may be overridden by --gopath flag on command line. flag.StringVar(&gopath, "gopath", gopath, "override default GOPATH") }
-
for Loop --> refer effective go _ blank identifier range of slices or maps use
make()
to initialize map/slice/chan -
Test Cases should cover both corerct values and incorrect values
- It should expect errors are also handled properly, meaning a test case should include test functions to check if the errors are returned properly.
- For a the test case for the wrong argument, if the function does not return proper error, it means the function does not handle the error and the test case failed.