Go R1 Day 31
progress๐
- Learned a bit about idiomatic patterns wtih error handling.
- Learned about inline block intiailization of variables using
if err := method(); err != nil {...}
approach. - Considered a bit more idiomatic patterns when I noticed excessibe nested if blocks.
tfdir := tf.Params().String("tfdir")
if tfdir != "" {
tf.Logf("tfdir set to: [%s]", tfdir)
} else {
tf.Errorf("๐งช failed to get tfdir parameter: [%v]", tfdir)
}
This would probably be more in alignment with Go standards by writing as:
tfdir := tf.Params().String("tfdir")
if tfdir == "" {
tf.Errorf("๐งช failed to get tfdir parameter: [%v]", tfdir)
return
}
tf.Logf("tfdir set to: [%s]", tfdir)
This reduces the noise and keeps things pretty flat.