I understand, thanks.
On Sat, Aug 26, 2023, 18:47 Brian Candler wrote:
> In both cases, the argument inside parenthesis is evaluated at the time
> "defer" is executed - as indeed is the value of "p".
>
> In the first case, you wrote "defer p.close(err)". Since err is nil at
> this point, at the
In both cases, the argument inside parenthesis is evaluated at the time
"defer" is executed - as indeed is the value of "p".
In the first case, you wrote "defer p.close(err)". Since err is nil at
this point, at the end of the function body, p.close(nil) is called.
In the second case, you wrote
Well here is the code that works as I need, what is wrong with the previous
one ?
https://go.dev/play/p/ZW-GmEP5uqu
package main
import (
"fmt"
)
type process struct {
}
func (p *process) close(err any) {
v, _ := err.(*int)
if *v == 1 {
fmt.Println("error")
} else {
fmt.Println("no error")
}
}