用 %w 包装错误

版本新特性 / Go 1.13

import (
    "errors"
    "fmt"
)

// *** before: ***
func readConfig() error {
    err := errors.New("file not found")
    return fmt.Errorf("read config: %v", err)
}
// the original error is lost, nothing further down can compare with it

// *** in version 1.13: ***
var ErrNotFound = errors.New("file not found")

func readConfig() error {
    return fmt.Errorf("read config: %w", ErrNotFound)
}