Error-Handling Scheme with Closures
This lesson discusses closures for error-handling purposes in detail.
We'll cover the following...
Whenever a function returns, we should test whether it results in an error: this can lead to repetitive and tedious code. Combining the defer/panic/recover mechanisms with closures can result in a far more elegant scheme that we will now discuss. However, it is only applicable when all functions have the same signature, which is rather restrictive. A good example of its use is in web applications, where all handler functions are of the following type:
func handler1(w http.ResponseWriter, r *http.Request) { ... }
Suppose all functions have the signature: ...