いまさらながら、なるほどーと思ったのでメモ。
go1.13のerrorsのUnwrap関数が以下のように実装されている
// Unwrap returns the result of calling the Unwrap method on err, if err's // type contains an Unwrap method returning error. // Otherwise, Unwrap returns nil. func Unwrap(err error) error { u, ok := err.(interface { Unwrap() error }) if !ok { return nil } return u.Unwrap() }
error型を型アサーションして、okじゃなかったらUnwrapが実装されていないのでnilを返却する。
okだったらerrorのUnwrap関数を実行して返却する。
なるほどね。