// isError returns whether or not the provided type implements the error interface func isError(typ types.Type) bool { if typ == nil { return false } // 获取 error 接口的类型 errorInterface := types.Universe.Lookup("error").Type().Underlying().(*types.Interface) // 判断 typ 是否实现了 error 接口 return types.Implements(typ, errorInterface) }